Parsing ASP.Net controls to HTML markup

travisowens

Centurion
Joined
Feb 11, 2004
Messages
108
Location
Rochester, NY
I have a table object that I created in my application and I need to extract the HTML markup from it. Is there a way to have ASP.Net parse Web Controls to HTML markup so I can munipulate the markup within my application?

I need something generic, not specific to just Table objects.

If nothing existis internal to .Net (but I would be surprised if the ASP.Net rendering engine isn't exposed) then I would need a free solution (even if I have to roll my own). Preferably I would hope if the HTML engine is exposed it would also render the HTML in a way compatible to the current user's browser, like how ASP.Net web forms work already.
 
Yes, simply render the controls.

Code:
[url=http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWebUIControlClassRenderControlTopic.asp]Control.RenderControl[/url](writer)
 
At this point I'm experimenting with the following code but my HTML just doesn't seem to be generating. I'm doing a response write to see if the HTML is being written.

Code:
			Table menu = new Table();
			TableRow row = new TableRow();
			TableCell cell = new TableCell();
			cell.Text = "TestCell";
			row.Cells.Add(cell);
			menu.Rows.Add(row);
			
			String body = String.Empty;
			String subject = String.Empty;
			//Control control = null;
			StringWriter sw = new StringWriter();
			HtmlTextWriter writer = new HtmlTextWriter(sw);

			menu.RenderControl(writer);
			body = sw.GetStringBuilder().ToString();
			
			if (writer != null) writer.Close();
			if (sw != null) sw.Close();
			
			Response.Write(body);
 
Last edited:
Back
Top