ASP. Net principles ViewState

Source: Internet
Author: User

Let's talk about the running principle of ViewState today.

Like Cookie, ViewState is a client state persistence mechanism. Different sessions are server-side state persistence mechanisms.
It is worth mentioning that ViewState is a special State persistence mechanism in. Net that is not available in other languages !!

ViewState is not the same as Session. All data types support ViewState only.
String Intger Boolean Array ArrayList Hashtable

When the page is closed, the ViewState does not exist, so the ViewState is stored in the browser cache.

The ViewState scope is "Page-level"
How can this sentence be understood? Let me give you an example.
If a ViewState is created on the page Default. aspx, the value of ViewState can only be used on the page Default. aspx.
Other pages cannot be used, just like a global variable.


If you want to say ViewState, you won't say "Hide domain"
What is a hidden domain?
A simple understanding is that when a hidden area passes values between pages, the user cannot see the existence of the hidden domain.
It can also be understood as a variable, but this variable cannot be seen on the interface !!

To use VIewState, you must use "Hide domain" to implement

Now let's talk about the principle of ViewState.
It is very easy to create a ViewState first.

 

Note that if ViewState exists, runat = "server" must be added, because only click "Submit" (submit form) hiding a domain can work. Otherwise, it will be the same as a common HTML Tag.

 

 

View the schematic diagram

Next I will briefly introduce the principle of ViewState.
1. the browser requests the Default. aspx page
2. When the ViewState created is found on the server side, a name named _ VIEWSTATE is automatically created (the dual Slide lines are all capitalized)
After base64 encryption, the value of the hidden domain is returned to the browser.
Completed in the SaveAllState method of the SaveState event
3. When the browser submits a form, the hidden fields of _ VIEWSTATE are also submitted to the server. At this time, the ReadState event of the page lifecycle is reported.
The ReadAllState method of will decrypt the encrypted value against base64 and assign the value to the ViewState named name.
4. Finally, operate the value in ViewState.


Let's take a look at the generated _ VIEWSTATE (browser version IE9)

 

I used ViewStateDecoder2 (ViewState viewer) to check the value.


It seems that I was right. As to why I want to encrypt my younger brother, I am still checking the information. Please kindly advise me .....

The above is my understanding of ViewState. Due to my limited personal abilities, I am sure there is something wrong. Please point it out so that I can continue to learn from my younger brother. Thank you very much !!!!!!


 

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.