ViewState of how to save state in a program

Source: Internet
Author: User
Tags server memory

There are several ways to save states in a program:

1, Application 2, Cookie 3, Session

4, Viewstate:viewstate is one of the ways to save the state, ViewState is actually a hidden field, but it is the base of the server control state Save the following code

1<form method="Post"action="./pay.aspx"Id="Form1">2<divclass="Aspnethidden">3<input type="Hidden"Name="__viewstate"Id="__viewstate"Value="/wepdwujodizotmwmdc3zgtbie1qcr6o1manjf5bvd8tp0akjjg+nyiebaajmcsw1g=="/>4</div>5 6<divclass="Aspnethidden">7 8<input type="Hidden"Name="__viewstategenerator"Id="__viewstategenerator"Value="5202eda5"/>9<input type="Hidden"Name="__eventvalidation"Id="__eventvalidation"Value="/wedaazxxrmso2fjzvl8lcmbbtgwotatqtf3v7tpu4yyc7csy5q9qbaazgdyvfktqztyqsoek/ dekjveubuclcdqacxyqvnj9g9la52g6r1ve+rc/jos/xayrhueladr6lbkoxga3o7hmb7g//qtmfx5owof4j8cn3f8fns8a+xdjyvbcg== "/>Ten</div> One</form>

This is a section of ViewState saved page code, in order to deal with complex features on the page, often add a lot of hidden, and then the backend server side in the ID based on the value received to determine the status of the page.

Similar to this can be implemented in viewstate way. ViewState is a better way to save data.

ViewState Assignment: viewstate["id"] = ' 123 ';

ViewState value: String bbid = viewstate["id"]. ToString ();

The difference between the ViewState and the session

(1) The session value is stored in the server memory, then, it is certain that a large number of use of the session will result in heavier server burden. Instead of ViewState server resources by simply depositing data into a page-hidden control, we can save variables and objects that require the server to "remember" into viewstate. Sesson should only be applied to variables and object stores that require cross-pages and are related to each access user.

(2) The session expires in 20 minutes by default, and ViewState never expires.

But ViewState is not able to store all of the. NET type data, it only supports string, Integer, Boolean, Array, ArrayList, Hashtable, and some types of customizations.

ViewState advantages: Storing in the client will relieve the burden on the server.

It is recommended not to store more confidential information, because viewstate to be saved on the client, there is inherent security risks.

If there is any place not correct, please correct me thank you!

ViewState of how to save state in a program

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.