Istatemanager interface under view status Mechanism

Source: Internet
Author: User

Istatemanager interface under view status Mechanism

This article is excerpted from the book Ding Jie Niu: vertically cutting ASP. NET 3.5 controls and component development technology

 

. The. NET Framework provides a system for custom view status management. web. UI. the istatemanager interface defines the attributes and methods that must be implemented by any class to support view status management of server controls. The view status of server controls consists of the accumulative values of control properties. This interface includes a method to save and load the view status value of the server control, and a method that instructs the control to track its view status changes. The members of this interface have the same semantics as the corresponding methods in the control class.
To customize the way ASP. NET applications manage the Server Control view status, you must create a class to implement this interface. The Code is as follows:
/// <Summary>
/// For more information about this book, see:
// Http://blog.csdn.net/ChengKing/archive/2008/08/18/2792440.aspx
/// </Summary>
Public interface istatemanager
{
// Methods
Object saveviewstate ();
Void loadviewstate (Object State );
Void trackviewstate ();

// Properties
Bool istrackingviewstate {Get ;}
}
This interface includes the following members:
Saveviewstate: saves all server control view state changes that have occurred since the page is sent back to the server, and returns the view State object after the latest change. If there is no view status associated with the control, this method returns NULL. After the view status is saved, the page class converts the view status objects of all controls to base64 format strings that can be transmitted over the network, the string object is returned to the client as a variable stored in the hidden element. When you use a custom view status, you can use the saveviewstate and loadviewstate combinations to manage the status.
Loadviewstate: restores the view information of the previous page saved by the saveviewstate Method to the complex properties of the control.
Trackviewstate: This method is automatically called when the init event ends during the lifetime of the server control. This method is called when the Development template data is bound to the control. This method reminds ASP. NET to monitor changes to the server control view status. If the control does not call the trackviewstate () method, the modification to the control property will not be added to the _ viewstate hidden domain. The next time the page is sent back, the property of the control is only restored to the old value. In terms of performance, in order to reduce the amount of transmission on the network, you should only save "changed" data to the view State, that is, this method is called only for data that needs to be saved to the view. In fact, trackviewstate only controls a Boolean value for marking. When adding data to a view, it determines whether the value is true. If it is true, it is added to the view data. The following section describes the internal principles of the statebag class.
Istrackingviewstate: returns whether the current control view is monitored by the ASP. NET Framework (whether to store this attribute in the view, which is controlled by the trackviewstate method ).
You may think that you have used view storage attribute values before when developing controls, for example, viewstate ["text"], but have not used the istatemanager interface control. Why is this true? The cause is described in section 6.2.3. In fact, it also uses the istatemanger interface, but control provides more convenient management.

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.