Server control html

  • Thread starter Thread starter vikram
  • Start date Start date
V

vikram

How can i get html generated by a web server control in
the code behid page itself.
i want to store the html in some variable for some
purpose. is it possible.
 
This is difficult because some controls dynamically render based upon the
conditions of the request -- primarily based upon browser version. You can
always do some screen scraping to gather the raw HTML output.

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
Hello Vikram,

You could do something like this:

[C#]
using (StringWriter writer = new StringWriter())
{
HtmlTextWriter hw = new Html32TextWriter(writer);
myControl.RenderControl(hw);
}

writer.ToString() contains your controls HTML

Keep in mind that as Brock said, some controls alter their output based on
browser versions, so this may not help you in accomplishing your goals.
 
Try this code:

Dim SB as New StringBuilder()
Dim SW as New StringWriter(SB)
Dim htmlTW as New HtmlTextWriter(SW)
MyControl.RenderControl(htmlTW)
Dim MyHTML 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