如何以编程方式检索ASP .NET中为Web控件呈现的html?
例如:
dim controlHTML as string = myControl.GetHTML()
答案 0 :(得分:6)
System.Text.StringBuilder sb = new System.Text.StringBuilder();
using (System.IO.StringWriter sw = new System.IO.StringWriter(sb))
using (System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw))
{
mycontrol.RenderControl(hw);
}
答案 1 :(得分:4)
你必须实际调用它.RenderMethod,然后传入一个HtmlTextWriter,并从中获取内容。