如何在ASP.NET中检索控件的呈现html?

如何在ASP.NET中检索控件的呈现html?,asp.net,Asp.net,如何以编程方式检索ASP.NET中为web控件呈现的html 例如: dim controlHTML as string = myControl.GetHTML() 您必须实际调用它的.RenderMethod,并传入一个HtmlTextWriter,然后从中获取内容 System.Text.StringBuilder sb = new System.Text.StringBuilder(); using (System.IO.StringWriter sw = new System.IO.S

如何以编程方式检索ASP.NET中为web控件呈现的html

例如:

dim controlHTML as string = myControl.GetHTML()

您必须实际调用它的.RenderMethod,并传入一个HtmlTextWriter,然后从中获取内容

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);
}