Asp.net output page content on the server

Source: Internet
Author: User

1. Define page content

View code

<Asp: Content ID = "  Bodycontent  " Runat = "  Server  " Contentplaceholderid = "  Maincontent  " > <Asp: Panel id = "  Resultdiv  " Runat = " Server  " > <H2> Welcome to ASP. NET ! </H2> <p> To learn more about ASP. NET <A href = "  Http://www.asp.net  " Title = "  ASP. NET Website  " > Www.asp.net </a> . <Asp: textbox id = "  Textbox1 " Runat = "  Server  " TEXT = "  GSW  " > </ASP: textbox> </P> <p> You can also find <A href = "  Http://go.microsoft.com/fwlink? Linkid = 152368  "  Title = "  Msdn ASP. NET File " > ASP. NET files on msdn </a> . </P> </ASP: Panel> <asp: button id = "  Button1  " Runat = "  Server  " TEXT = "  Button  " Onclick = "  Button#click  " /> </ASP: content>

2. Rewrite the render Method
CodeAs follows:

View code

  Protected   Override   Void  Render (htmltextwriter writer) {stringwriter SW; htmltextwriter htmltw; SW = New  Stringwriter (); htmltw = New  Htmltextwriter (SW );  Base  . Render (htmltw ); //  Htmltw = writer; Stringbuilder temp = Sw. getstringbuilder ();  //  Base. Render (writer );              String Pageresult = Temp. tostring (); writer. Write (pageresult); system. Io. streamwriter strwrite = New Streamwriter (server. mappath ( "  A.html  " ); Strwrite. Write (pageresult); strwrite. Close ();} 

The above code outputs the entire page to HTML.

3. You can specify the content of the server control and output it as HTML.

3.1 override verifyrenderinginserverform

The Code is as follows:

 
Public Override VoidVerifyrenderinginserverform (Control ){Return;}

3.2 rewrite the render Method

  Protected   Override   Void  Render (htmltextwriter writer ){ Base  . Render (writer); system. Text. stringbuilder strbuilder = New  System. Text. stringbuilder (); system. Io. stringwriter ostringwriter = New  System. Io. stringwriter (strbuilder); system. Web. UI. htmltextwriter ohtmltextwriter = New  System. Web. UI. htmltextwriter (ostringwriter); strbuilder. append (  " <HTML>   "  ); Resultdiv. rendercontrol (ohtmltextwriter); system. Io. streamwriter strhtmlfile = System. Io. file. createtext (server. mappath ( "  A.html  "  ); Strbuilder. append (  "  </Body>   " ); Strhtmlfile. writeline (strbuilder. tostring (); strhtmlfile. Close ();} 

 

Related Article

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.