Asp.net 2.0 中获取控件输出的Html代码 (转)
将Asp.net 控件的呈现html获取,在不少场合会用到,比如生成静态页时
以下代码选自 Asp.net 2.0 高级编程
转自:Asp.net 2.0 中获取控件输出的Html代码
public static string RenderControlAsString(Control ctl)
{
StringWrite sw=new StringWrite();
HtmlTextWrite write=new HtmlTextWrite(sw);
ctl.RenderControl(writer);
string str =sw.ToString();
write.Close();
sw.Close();
return str;
}
{
StringWrite sw=new StringWrite();
HtmlTextWrite write=new HtmlTextWrite(sw);
ctl.RenderControl(writer);
string str =sw.ToString();
write.Close();
sw.Close();
return str;
}