Thursday, March 22, 2012

html code of web controls

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?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
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;
}

No comments:

Post a Comment