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>