How to retrieve the rendered html for a control in ASP.NET?

asp.net

Solution

System.Text.StringBuilder sb = new System.Text.StringBuilder();
using (System.IO.StringWriter sw = new System.IO.StringWriter(sb))
using (System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(sw))
{
    mycontrol.RenderControl(hw);
}

Problem

How do I retrieve the html rendered for a web control in ASP .NET programmatically? For instance something like: ``` dim controlHTML as string = myControl.GetHTML() ```

Original source