1、自定义加载用户控件
ceshi.aspx页面
<html> <body>
<div id="divControls" runat="server"></div>
</body> </html>
ceshi.aspx.cs页面
System.Web.UI.UserControl newUC = (System.Web.UI.UserControl)Page.LoadControl("ceshi.ascx");
divControls.Controls.Add(newUC);
2、把用户控件转换为html字符串
Page page = new Page();//这里新建了一个page对像,不是当前的page对像
System.Web.UI.UserControl control = (System.Web.UI.UserControl)page.LoadControl("ceshi.ascx");
page.Controls.Add(control);//在新建的page对像中加载进去
System.IO.StringWriter tw = new System.IO.StringWriter();
HtmlTextWriter wt = new HtmlTextWriter(tw);
page.RenderControl(wt);//在新建的page对像 输出html
Response.Write(tw.ToString());