3

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()

2 Answers 2

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

Comments

4

You have to actually call it's .RenderMethod, and pass in a HtmlTextWriter, and get the contents from that.

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.