Thursday, October 16, 2008

Rendering a Control to a String

This is a really handy little function for rendering a control to a string. Really handy if you want to pass back rendered HTML from a StaticPageMethod or WebService.

private static string GetRenderedControl(Control control)
{
HtmlTextWriter writer = new HtmlTextWriter(new StringWriter());
control.RenderControl(writer);
return writer.InnerWriter.ToString();
}

No comments: