Here is a simple way to do it. We can implement this by overriding the Render method of the Page class.

protected override void Render(HtmlTextWriter writer)

{

System.Text.StringBuilder sb = new System.Text.StringBuilder();

System.IO.StringWriter sw = new System.IO.StringWriter(sb);

HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);

base.Render(htmlWriter);

 

//The HTML output is stored in the string object. Use it the way you want.

string PageHTML = sb.ToString();

writer.Write(PageHTML);

}


 

ADDITIONAL INFORMATION:

========================

We can also add or modify the response content in this method.

Check http://msdn2.microsoft.com/en-us/library/system.web.ui.control.render.aspx for details about Render method.