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

时间:2009-10-28 14:26:47

标签: asp.net

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

例如:

dim controlHTML as string = myControl.GetHTML()

2 个答案:

答案 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,并从中获取内容。