In ASP. NET, how does one control the generated HTML content stream?

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.