Remove viewstate to improve website performance

Source: Internet
Author: User
Tags website performance

Rewrite the render method to remove viewstate and improve website performance.

System. Io. stringwriter html = New  System. Io. stringwriter (); system. Web. UI. htmltextwriter TW = New  System. Web. UI. htmltextwriter (HTML );  Base  . Render (TW );  String Temp = Html. tostring ();  String S1 = String . Empty, S2 = String . Empty, S3 =String . Empty, S4 = String . Empty, S5 = String . Empty, S6 = String  . Empty;  Int I = 0  ;  Int J = 0  ; I = Temp. indexof ( "  <Form  " );  If (I> 0  ) {J = Temp. indexof ( "  >  "  , I); S1 = Temp. substring ( 0  , I); S2 = Temp. substring (J + 1 , Temp. Length-j- 1  );} I = S2.indexof ("  <Input type = \ "Hidden \" name = \ "_ viewstate \" id = \ "_ viewstate \"  "  );  If (I> 0  ) {J = S2.indexof ( "  >  "  , I); S3 = S2.substring ( 0  , I); S4 = S2.substring (J +1 , S2.length-j- 1  );} I = S4.indexof ( "  <Input type = \ "Hidden \" name = \ "_ eventvalidation \" id = \ "_ eventvalidation \"  "  );  If (I> 0  ) {J = S4.indexof ( "  >  " , I); S5 = S4.substring ( 0  , I); S6 = S4.substring (J + 1 , S4.length-j- 1  ); Temp = S1 + S3 + S5 + S6 ;}  Else  {Temp = S1 + S3 + S4;} temp = Temp. Replace ( "  </Form> " , ""  ); Temp = Temp. Replace ( "  \ R \ n  " , ""  ); TW. Close (); response. Write (temp ); 

Reference: http://www.cnblogs.com/cmsdn/archive/2011/12/12/2285137.html

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.