Asp.net 2.0 中获取控件输出的Html代码
将Asp.net 控件的呈现html获取,在不少场合会用到,比如生成静态页时
以下代码选自 Asp.net 2.0 高级编程
public static string RenderControlAsString(Control ctl){
StringWrite sw=new StringWrite();
HtmlTextWrite write=new HtmlTextWrite(sw);
ctl.RenderControl(writer);
string str =sw.ToString();
StringWrite sw=new StringWrite();
HtmlTextWrite write=new HtmlTextWrite(sw);
ctl.RenderControl(writer);
string str =sw.ToString();
write.Close();
sw.Close();
return str;
}
}
posted on 2007-01-19 10:54 醒了又睡的鱼.NET 阅读(719) 评论(0) 编辑 收藏 举报