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 !!!!!!