Updated on 2007/07/19
What is viewstate? In short, viewstate maintains the web page UI state.
Before ASP. NET is born, it is necessary to keep the values of each HTML element in the same web page after it is returned (assuming it does not jump to other pages ).ProgramThe member himself has to do some work and assign values to the values of each HTML element. ASP. NET can automatically perform these complicated tasks. These are all attributed to viewstate. How does viewstate work?
In fact, there is nothing. After careful research, we will find that ASP. NET manages a hidden HTML element: <input type = "hidden" name = "_ viewstate">. When an Asp.net page is executed, the viewstate value of the page and the viewstate value of all controls will be encoded into a string and assigned to the hidden element as part of the HTML and sent to the client browser. After the client submits the page, the viewstate string (which may be changed on the client) will be returned again. On the server side, Asp. net analyzes and processes this viewstate string to replace the values of each control, so that the client operation element value is "intelligently" written down.
Of course, ASP. NET also leaves an interface for our engineers to change the viewstate value of a control, or you can store a viewstate as needed. For example:
Viewstate ["sortfield"] = value;
The difference between viewstate and session is:
| |
Session state |
Viewstate |
| Whether to occupy server resources |
Yes |
No |
| Timeout or not |
Yes. The default value is 20 minutes. |
No |
| Whether to store all. Net types |
Yes |
No, only limited to: strings, integers, booleans, arrays, arraylist, hashtable, custom typeconverters |
| Increase HTML transmission? |
No |
Yes |
Viewstate can be disabled in the following situations:
| Web pages |
Controls |
- Web page does not need to be returned
|
- You do not need to process events of a widget.
- The control does not have attributes that need to be dynamically set or that are dynamically bound to Data.
|
Two viewstate technologies are recommended.Article:
Http://msdn.microsoft.com/library/default.asp? Url =/library/en-US/dnaspnet/html/asp11222001.asp
Http://msdn.microsoft.com/msdnmag/issues/03/02/CuttingEdge/
And famous blogs
Http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/Truly-Understanding-Viewstate.aspx
In addition, I made a PPT ON THE Asp.net status management mechanism. You can download and view it here.