Asp.net generates static post-redundant code and removes the code generated by viewstate.

Source: Internet
Author: User

Looking at the source files compiled by your website, there are a lot of messy things in it, and you feel uncomfortable after reading it.
Copy codeThe Code is as follows: <input type = "hidden" name = "_ VIEWSTATE" id = "_ VIEWSTATE" value = "/wEPDwULLTE3NjgxMzM0MDIPZBYCZg9kFgIC ......
There is also the form source file. At first glance, we can see that it is an asp.net page.
Copy codeThe Code is as follows: <form name = "form1" method = "post" action = "smartDropDownList. aspx" id = "form1">
I know that my feet home is also made by ASP. NET. I took a curious look at the source files on the homepage of the blog garden and found that I didn't have these things. Then I asked someone else,

I also found some information online;

I summarized my thoughts:
1. If there is no complex data interaction on a page, for example, you can use ajax to log on, or remove a single news page, if there is a message, you can also use ajax to complete it!

2. The data interaction on the background management page is generally a little complicated. I feel that there is no need to remove anything. The background has no impact on SEO, I looked at the background of the blog garden with curiosity.
Paste the Code directly and add the following functions to your page code.
Copy codeThe Code is as follows:
Protected override void Render (HtmlTextWriter writer)
{
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 );
}

In fact, it is to rewrite the Render method, and then intercept the html source file to solve the problem. We can use the method in our own situation. I think it is easy to use!
If you think it is simple or disdainful, don't spray it. If you have any questions, please make a brick. Thank you!

2. The solution for querying foreigners is to move the code to the end, but some webpages report an error, and then the viewstate code of the webpage's enableviewatate = false is obviously reduced.

  Cause summary:
(1). This is because the. asp.net server control that records the control view State is recorded by default.
If you are sure that a control does not need to record the control status, you can assign a value of false to EnableViewState to disable the control.
  Personal summary:
Closing the view is not the final solution, but will reduce it. The most thorough solution is to make the form into a common html Tag.
Skip runat = "server. Although the program is important, it makes no sense if the program has no effect,
  Comments from netizens:
View status. This is not useless code. Why do you read the information in the form of a control object after each submission using a server control? Because of the view status.

The view status can be disabled, but it is incomplete to only use EnableViewState = false. You will also see the hidden field of _ VIEWSTATE on the page. This is because even if he is disabled, a server control will still be used there, that is, from runat = "server". If you program common html tags from, the page will be cleaned.

Of course, disabling the view State will improve the system efficiency, because the program will no longer analyze the value of the view state, and then initialize the control object. This is efficient for websites, but if it is a reference program, it is a bit difficult.

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.