Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET modifing the HTML of a page before it is sent to the client

Tags:

html

asp.net

I need to catch the HTML of a ASP.NET just before it is being sent to the client in order to do last minute string manipulations on it, and then send the modified version to the client.

e.g.

The Page is loaded Every control has been rendered correctly The Full html of the page is ready to be transferred back to the client

Is there a way to that in ASP.NET?

like image 706
Nikola Stjelja Avatar asked Nov 10 '08 15:11

Nikola Stjelja


1 Answers

You can override the Render method of your page. Then call the base implementation and supply your HtmlTextWriter object. Here is an example

protected override void Render(HtmlTextWriter writer)
{
    StringWriter output = new StringWriter();
    base.Render(new HtmlTextWriter(output));
    //This is the rendered HTML of your page. Feel free to manipulate it.
    string outputAsString = output.ToString();

    writer.Write(outputAsString);
}
like image 182
Atanas Korchev Avatar answered Sep 22 '22 09:09

Atanas Korchev