ASP. NET-maintain viewstate

Source: Internet
Author: User
Tags classic asp

Maintain viewstate)

 

When a form in classic ASP is submitted, all form values are cleared. Imagine that you submitted a form with a large amount of information, and the server returned an error. You will have to return the form and correct the information. After you click the back button, what will happen? All the form values are cleared, and you have to start everything again. The site does not maintain your viewstate.

When a form in ASP. NET is submitted, the form reappears with all the form values. 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. By placing a hidden field in a <form runat = "server"> Control on each page, we can define the page status.Source codeIt may be like this:

 
<Form name = "_ ctl0" method = "Post" Action = "page. aspx "id =" _ ctl0 "> <input type =" hidden "name =" _ viewstate "value =" ddwtnti0odu5mde1ozs + Signature = "/> ..... some Code </form>

Maintaining viewstate is the default setting of ASP. NET web forms. If you do not want to maintain viewstate. the top part of the ASPX page contains commands: <% @ page enableviewstate = "false" %>, or you can add an attribute for any control: enableviewstate = "false ".

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

<HTML> <body> <form action = "demo_classicasp.aspx" method = "Post"> your name: <input type = "text" name = "fname" size = "20"> <input type = "Submit" value = "Submit"> </form> <% dim fnamefname = request. form ("fname") if fname <> "" thenresponse. write ("hello" & fname &"! ") End if %> </body>  

Tiy

This is the new ASP. NET method. When you click the submit button, the form value does not disappear:

 
<SCRIPT runat = "server"> sub submit (sender as object, e as eventargs) lbl1.text = "hello" & txt1.text &"! "End sub </SCRIPT> <HTML> <body> <form runat =" server "> your name: <asp: textbox id = "txt1" runat = "server"/> <asp: button onclick = "Submit" text = "Submit" runat = "server"/> <p> <asp: label id = "lbl1" runat = "server"/> </P> </form> </body>  
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.