一网友刚才在SKYPE问及Insus.NET,他需要在后台动态创建一些Web控件,也能正常显示于aspx页面上。但要把这些动态创建的代码存入数据库,存是没有问题,问题是存储的代码不是创建时写的Web代码,而是需要html代码,也就是aspx运行时,右击mouse 菜单View Source...看到的。
问题分析起来,就是怎样把Web控件代码转换为Html代码。参考下面代码示例:
示例代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
TextBox textbox = new TextBox();
textbox.ID = "TextBox1";
textbox.Text = "Insus.NET";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
textbox.RenderControl(htw);
string html = sw.ToString();
textbox.ID = "TextBox1";
textbox.Text = "Insus.NET";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
textbox.RenderControl(htw);
string html = sw.ToString();