View status is a method used by default by the ASP. NET page framework to save the page and control value between the round-trip process. When the page is displayed in HTML format, the current status and value of the page to be retained during the sending-back process will be serialized as a base64 encoded string and output to a hidden field in the view status.
The view status is the repository on the ASP. NET page. You can store the values that need to be retained during the sending-back process. For example, you can store the information in the view status. The next time you send the page to the server, the information will be accessed during page loading events.
You can use the viewstate attribute of the page (which exposes a dictionary object) to access the view State information. View State data is stored as strings, so only serialized objects can be stored.
View status data is stored in one or more hidden fields in base64 encoded string format. You can use the viewstate attribute of the page (which exposes a dictionary object) to access the view State information. View State data is stored as strings, so only serialized objects can be stored.
Because the view status is sent as a hidden field, you can change the view status until the prerendercomplete event occurs. Once the page is displayed in the browser, you cannot save changes to the view status.
If you view the page output source, you can see information in the hidden view Status field, which may cause security issues. To alleviate this problem, you can encrypt the view status by setting the viewstateencryptionmode attribute in the @ page command to "always.
Note:
To use the viewstate attribute, an ASP. NET webpage must contain a form element with the runat = "server" attribute.
Data types that can be stored in view status
You can store the following types of objects in the view State:
String
Integer
Boolean Value
Array object
Arraylist object
Hash table
Custom type converter (see typeconverter class)
You can also store other types of data, but you must use the serializable attribute to compile the class so that the view State can serialize the data into XML.
Considerations for using view status
View status provides the status information of a specific ASP. NET page. If you need to use information on multiple pages, or if you need to retain the information when accessing the Website, you should use another method (such as the applicationProgramStatus, session status, or personalized settings) to maintain the status.
View status information is serialized into XML and encoded using base64 encoding, which generates a large amount of data. When a page is sent back to the server, the view status content is sent as part of the page sending information. If the view status contains a large amount of information, the page performance will be affected.
Another important factor is that, if the amount of data in the hidden field is too large, some proxies and firewalls will prohibit access to pages containing the data. Because the maximum number varies with the firewall and proxy used, a large number of hidden fields may cause unexpected problems. To help avoid this problem, if the volume of data stored in the viewstate attribute exceeds the value specified in the maxpagestatefieldlength attribute of the page, the page splits the view status into multiple hidden fields, to reduce the size of each individual field to a value lower than that rejected by the firewall.
Some mobile devices do not allow hidden fields at all. Therefore, the view status is invalid for these devices.
Read value from view status
On the pageCodeSet the value of the variable in the viewstate attribute.
The following code example shows how to obtain an arraylist object named arraylistinviewstate from the view state, and then bind the gridview control to the object as a data source.
Arraylist = new arraylist ();
Arraylist = (arraylist) viewstate ["arraylistinviewstate"];
This. gridview1.datasource = arraylist;
This. gridview1.databind ();
The value in view status is converted to string type. As shown in this example. In C #, when you read the view status value, it should always be forcibly converted to the appropriate type.
If you try to obtain a value from a view that never exists, no exception is thrown. To ensure that the required value is in the view State, first use the test (for example, the following test) to check whether the object exists:
If (viewstate ["color"] = NULL)
// No such value in view State, take appropriate action.
Save the value to view status
The following example shows how to store and retrieve the text attributes of values from the viewstate attribute of the control.
Private const int defaultfontsize = 3;
// Add property values to view State with set;
// Retrieve them from view State with get.
Public String text
{
Get
{
Object o = viewstate ["text"];
Return (O = NULL )? String. Empty: (string) O;
}
Set
{
Viewstate ["text"] = value;
}
}
Encrypted view status
In the @ page command, set the viewstateencryptionmode attribute to "always", as shown in the following example:
<% @ Page viewstateencryptionmode = "always"... %>
Http://aierong.cnblogs.com
SQL server2005 Transact-SQL new weapon learning Summary-Summary
Ms SQL database backup and recovery stored procedures (enhanced)
SQL Server Distributed Query essay (sp_addmediaserver) and remote login ing (sp_addmediasrvlogin) use small summary)
Summary of the implementation of ASP. net2.0 internationalization/localization applications (multi-language, multi-cultural page implementation)
WAP development data station (latest update)
Custom Format String (implementation of the three interfaces of iformattable, iformatprovider, and icustomformatter)
Asynchronous programming of mcad learning notes (asynccallback delegation, iasyncresult interface, begininvoke method, and endinvoke method)
Mcad learning notes: Calling class methods through reflection, attention, fields, indexers (2 methods)
Serialization of mcad learning notes (binary and soap serialization)
Delegated re-understanding of mcad learning notes (discussion of Delegate constructor, begininvoke, endinvoke, and invoke4 methods)
Winform development, form display, and form value passing knowledge
Microsoft Windows service using mcad Study Notes
Copy all the objects and files under a certain category to the target category (number of objects)
ASP. NET status management (Summary)