Getting the HTML for a control

  • Thread starter Thread starter Chad
  • Start date Start date
C

Chad

Your gonna ask why would I want to...

One reason is that the unsupported MS Web Tree Control has a text property
on a node, but no Controls collection. To add a control to the node, I need
its HTML, or I need to build it myself (i'd rather not)

Somebody suggested I take a look at the HTML in the OnRender() method.

Sorry to be slow, but how would I get the html for a TextBox control, for
example?

I see a PreRender event..
 
Chad said:
Sorry to be slow, but how would I get the html for a TextBox control, for
example?
Do this:

//Render the control
TextBox tbx = new TextBox();
tbx.Text = "Hello World!";
HtmlTextWriter writer = new HtmlTextWriter(new StringWriter());
tbx.RenderControl(writer);
// Get the HTML markup
htw.InnerWriter.ToString();

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
 
Try this code:

Dim SB as New StringBuilder()
Dim SW as New StringWriter(SB)
Dim htmlTW as New HtmlTextWriter(SW)
MyTextBox.RenderControl(htmlTW)
Dim TextBoxHTML as String = SB.ToString()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top