PDA

Click to See Complete Forum and Search --> : html code of web controls


ey316
Nov 18th, 2003, 01:43 AM
is there any way i can get the corresponding HTML code of a web control?

For example, i have an asp.net table with w/ one row and one cell with the text "sample". I want to get this string:

"<table><tr><td>sample</td></tr></table>"

Is this possible?

persianboy
Nov 18th, 2003, 02:52 PM
i guess you could put the web control on your page, press the run button,then right click on the webbrowser,nd in the context menu click view source, you can find the html code for you control there

ey316
Nov 18th, 2003, 10:31 PM
Yeah, but I need to retrieve the html code from the program. Anyway, I have already solved it. Here's the code I used:

//returns the html code of the specified web control
public static string RenderHTML(System.Web.UI.WebControls.WebControl control)
{

StringBuilder SB = new StringBuilder();
System.IO.StringWriter SW = new System.IO.StringWriter(SB);
System.Web.UI.Html32TextWriter htmlTW = new Html32TextWriter(SW);
control.RenderControl(htmlTW);
string html = SB.ToString();
return html;
}