If I create a UserControl and add some objects to it, how can I grab the HTML it would render?
ex.
UserControl myControl = new UserControl(); myControl.Controls.Add(new TextBox()); // ...something happens return strHTMLofControl;
I’d like to just convert a newly built UserControl to a string of HTML.
You can render the control using
Control.RenderControl(HtmlTextWriter).Feed
StringWriterto theHtmlTextWriter.Feed
StringBuilderto theStringWriter.Your generated string will be inside the
StringBuilderobject.Here’s a code example for this solution: