by Marius Gheorghe
17. April 2006 21:16
Sometimes you need to capture the page HTML output (for logging purposes or to mail it). The easiest way to do it is to override the Render event handler like this :
protected override void Render(HtmlTextWriter writer)
{
//create a new string builder
StringBuilder builder = new StringBuilder();
//create a StringWriter based on the builder
StringWriter sw= new StringWriter(builder);
//create a new HmtlTextWriter based on the string writer
HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
//call the base Page implementation which generates the HTML
base.Render(htmlWriter);
//get the output from the string
string html = builder.ToString();
//do usefull stuff
}