ASP. NET Web Forms-maintain ViewState and formsviewstate

Source: Internet
Author: User
Tags classic asp

ASP. NET Web Forms-maintain ViewState and formsviewstate

ASP. NET Web Forms-maintain ViewState

By maintaining the ViewState of an object in your Web Form, you can save a lot of coding work.

Maintain ViewState)

In classic ASP, when a form is submitted, all form values are cleared. Assume that you have submitted a form with a large amount of information, and the server returns an error. You have to return to the form to correct the information. You click the return button, and then all the form values are cleared. You have to start everything again! The site does not maintain your ViewState.

In ASP. NET, when a form is submitted, the form appears in the browser window together with the form value. How can we do this? This is because ASP. NET maintains your ViewState. ViewState indicates its status when the page is submitted to the server. In this status

Each page of the control contains a hidden domain definition. The source code is as follows:

... Some code

Maintaining ViewState is the default setting of ASP. NET Web Forms. If you do not want to maintain ViewState, please include the command <% @ Page EnableViewState = "false" %> at the top of the. aspx Page, or add the attribute EnableViewState = "false" to any control ".

See the. aspx file below. It demonstrates the running mode of "old. When you click the submit button, the form value disappears:

Instance

Your name:

<%

Dim fname

Fname = Request. Form ("fname ")

If fname <> "" Then

Response. Write ("Hello" & fname &"! ")

End If

%>

The following is the new ASP. NET method. When you click the submit button, the form value will not disappear:

Instance

Click view source code in the framework on the right of the instance. You will see that ASP. NET has added a hidden field to the form to maintain the ViewState.

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.