Asp. NET development, sometimes you need to control the final HTML Source Code output on the page, which is easily implemented in the page render method. The following is an implementation method. The annotations are all in Code .
<% @ Page Language = "C #" %> <br/> <% @ import namespace = "system. Io" %> <br/> <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <br/> <SCRIPT runat = "server"> <br/> protected override void render (htmltextwriter writer) <br/>{< br/> string content = string. empty; <br/> stringwriter = new stringwriter (); <br/> htmltextwriter htmlwriter = new htmltextwriter (stringwriter ); <br/> try <br/>{< br/> // present the content of the current page to a temporary htmltextwriter object <br/> base. render (htmlwriter); <br/> htmlwriter. close (); <br/> // obtain all content on the current page <br/> content = stringwriter. tostring (); <br/> // replace some content on the page <br/> string newcontent = content. replace ("[mxh]", "Meng xianhui"); <br/> // display the content of the new page <br/> writer. write (newcontent); <br/>}< br/> catch {}< br/> finally <br/>{< br/> stringwriter. dispose (); <br/> htmlwriter. close (); <br/> htmlwriter. dispose (); <br/>}< br/> </SCRIPT> <br/> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead id = "head1 "runat =" server "> <br/> <title> present content test on the Replace page of Meng xianhui </title> <br/> </pead> <br/> <body> <br/> <Form ID = "form1" runat = "server"> <br/> [mxh] <br/> </form> <br/> </ body> <br/> </ptml>