The StateBag Class and the IStateManager Interface

The client-side state management technique ViewState exists in the .NET Framework class hierarchy as a member property of the System.Web.UI.Control class called ViewState, of type StateBag, which implements a dictionary data structure to store name/value pairs. The StateBag class implements the interfaces in Table 3-3.

Table 3-3. Interfaces Implemented by the StateBag Class

Interface

Description

ICollection

Defines enumerators, synchronization methods, and size for collections

IDictionary

Specialized collection interface that implements a collection of

name/value pairs

IEnumerable

Provides the enumerator for iteration over a collection

IStateManager

Defines the properties and methods required to support ViewState manage-

ment in server controls

The interfaces ICollection and IEnumerable are standard interfaces used to give collection functionality to a class. IDictionary provides the name/value storage mechanism required when working with ViewState. IStateManager is the interface that handles all the tedious state maintenance functions during server-side processing and greatly contributes to the Visual Basic-like ease of programming model for ASP.NET web developers.

As you can see, the IStateManager interface is the most interesting interface implemented by the StateBag class, as it includes methods to load and save a control's data or state. Because all server controls descend from System .Web.UI.Control, the .NET Framework uses the methods and properties implemented by IStateManager to dehydrate controls before serialization into a hidden form field named_VIEWSTATE. Likewise, ASP.NET calls on IStateManager during postback to rehydrate server control objects for server-side processing.

0 0

Post a comment

  • Receive news updates via email from this site