I don't think there is an (easy) way to get at the final HTML of the page (there may be ways, possibly using HttpHandlers maybe, or some other post loading events, but this will be difficult to implement).
However, you could recreate the entire page on the fly in memory. Instead of, say, adding a DataGrid to the ASPX portion of the page, you can create one on the fly and bind your data to it. Then you can use the following method to get the control's HTML in a string:
Code:
public static string GetHtmlFromControl(Control aControl)
{
// Get the rendered HTML of a control
StringBuilder SB = new StringBuilder();
StringWriter SW = new StringWriter(SB);
HtmlTextWriter htmlTW = new HtmlTextWriter(SW);
aControl.RenderControl(htmlTW);
return SB.ToString();
}
I use this method quite a lot to send nicely formatted Html e-mail for error logging, shopping carts etc.
Check out the following article for more details:
http://aspnet.4guysfromrolla.com/articles/091102-1.aspx
(My method is comes from this article).
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.