获得用户控件html

mac2022-06-30  59

public static string getUControlHtml(string controlName) { StringBuilder build = new StringBuilder(); HtmlTextWriter htmlWriter = new HtmlTextWriter(new StringWriter(build)); UserControl uc = new UserControl(); Control ctrl = uc.LoadControl(controlName + ".ascx");//加载用户定义控件 htmlWriter.Flush(); string result; try { ctrl.RenderControl(htmlWriter); } catch { } finally { htmlWriter.Flush(); result = build.ToString(); } return result;//返回控件的HTML代码 }

 

转载于:https://www.cnblogs.com/daixingqing/p/3261664.html

最新回复(0)