Tuesday, December 20, 2005

...
Page page = new Page();
Control c = page.LoadControl("YourControl.ascx");
// do Something with your control, DataBind, ...

string html = RenderControl(c);

public static string RenderControl(Control ctrl)
{
   System.Text.
StringBuilder sb = new System.Text.StringBuilder();
   System.IO.
StringWriter tw = new System.IO.StringWriter(sb);
   System.Web.UI.
HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
   ctrl.RenderControl(hw);
   
return sb.ToString();
}