How would you create a new DropDownList (or any asp server control) and then render the html to a string in C#?
views:
53answers:
1
+3
A:
System.Web.UI.Control has a RenderControl(HtmlTextWriter) method that you can use to get the rendered content of the control as a string:
using(var sw = new System.IO.StringWriter()) // SW is a buffer into which the control is rendered
using(var writer = new HtmlTextWriter(sw))
{
myControl.RenderControl(writer);
return sw.ToString(); // This returns the generated HTML.
}
Matt
2009-11-18 16:33:29
awesome.Thanks.
Kenneth J
2009-11-18 16:54:08