0

How would you create a new DropDownList (or any asp server control) and then render the html to a string in C#?

0

1 Answer 1

4

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.
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.