After learning about the lifecycle of the Asp.net page, you may have the idea that the server can intercept the HTML to be output when HTML is output, I found a lot of information on the Internet and did not find the answer. I finally learned how to do it with the help of an expert. I 'd like to share it with you.
As we all know, in the lifecycle of a page, the last stage is rendering and executing the render event.
You can rewrite this method.
Protected override void render (htmltextwriter writer)
{
// Base. Render (writer );
System. Io. memorystream mem = new system. Io. memorystream ();
System. Io. streamwriter twr = new system. Io. streamwriter (MEM );
System. Web. UI. htmltextwriter mywriter = new htmltextwriter (twr );
Base. Render (mywriter );
mywriter. Flush ();
mywriter. Dispose ();
System. Io. streamreader strmrdr = new system. Io. streamreader (MEM );
Strmrdr. basestream. Position = 0;
String pagecontent = strmrdr. readtoend (); // obtain the HTML to be output
Strmrdr. Dispose ();
Mem. Dispose ();
// Set the breakpoint here to view the value of pagecontent
// Session ["htmlcode"] = pagecontent;
Writer. Write (pagecontent); write to the output stream
}