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.