StateBag Class
Manages the view state of ASP.NET server controls, including pages. This class cannot be inherited.
Assembly: System.Web (in System.Web.dll)
| Name | Description | |
|---|---|---|
![]() | StateBag() | Initializes a new instance of the StateBag class. This is the default constructor for this class. |
![]() | StateBag(Boolean) | Initializes a new instance of the StateBag class that allows stored state values to be case-insensitive. |
| Name | Description | |
|---|---|---|
![]() | Count | Gets the number of StateItem objects in the StateBag object. |
![]() | Item[String^] | Gets or sets the value of an item stored in the StateBag object. |
![]() | Keys | Gets a collection of keys representing the items in the StateBag object. |
![]() | Values | Gets a collection of the view-state values stored in the StateBag object. |
| Name | Description | |
|---|---|---|
![]() | Add(String^, Object^) | Adds a new StateItem object to the StateBag object. If the item already exists in the StateBag object, this method updates the value of the item. |
![]() | Clear() | Removes all items from the current StateBag object. |
![]() | Equals(Object^) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | GetEnumerator() | Returns an enumerator that iterates over all the key/value pairs of the StateItem objects stored in the StateBag object. |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetType() | |
![]() | IsItemDirty(String^) | Checks a StateItem object stored in the StateBag object to evaluate whether it has been modified since the call to Control::TrackViewState. |
![]() | Remove(String^) | Removes the specified key/value pair from the StateBag object. |
![]() | SetDirty(Boolean) | |
![]() | SetItemDirty(String^, Boolean) | |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
| Name | Description | |
|---|---|---|
![]() ![]() | ICollection::CopyTo(Array^, Int32) | For a description of this member, see ICollection::CopyTo. |
![]() ![]() | IDictionary::Add(Object^, Object^) | For a description of this member, see IDictionary::Add. |
![]() ![]() | IDictionary::Contains(Object^) | For a description of this member, see IDictionary::Contains. |
![]() ![]() | IDictionary::Remove(Object^) | For a description of this member, see Remove. |
![]() ![]() | IEnumerable::GetEnumerator() | For a description of this member, see IEnumerable::GetEnumerator. |
![]() ![]() | IStateManager::LoadViewState(Object^) | Restores the previously saved view state of the StateBag object. |
![]() ![]() | IStateManager::SaveViewState() | Saves the changes to the StateBag object since the time the page was posted back to the server. |
![]() ![]() | IStateManager::TrackViewState() | Causes the StateBag object to track changes to its state so that it can be persisted across requests. |
![]() ![]() | ICollection::IsSynchronized | For a description of this member, see ICollection::IsSynchronized. |
![]() ![]() | ICollection::SyncRoot | For a description of this member, see ICollection::SyncRoot. |
![]() ![]() | IDictionary::IsFixedSize | For a description of this member, see IDictionary::IsFixedSize. |
![]() ![]() | IDictionary::IsReadOnly | For a description of this member, see IDictionary::IsReadOnly. |
![]() ![]() | IDictionary::Item[Object^] | For a description of this member, see IDictionary::Item. |
![]() ![]() | IStateManager::IsTrackingViewState | Gets a value indicating whether state changes are being tracked. |
| Name | Description | |
|---|---|---|
![]() | AsParallel() | Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.) |
![]() | AsQueryable() | Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.) |
![]() | Cast<TResult>() | Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.) |
![]() | OfType<TResult>() | Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.) |
View state for a page or control is the cumulative property values, or view, of that page or control. You can access this class through the Control::ViewState property. Controls can also store essential state information in control state, but that information is not stored as a StateBag object.
This class is the primary storage mechanism for all HTML and Web server controls. It stores attribute/value pairs as strings associated with the control. It tracks changes to these attributes only after the OnInit method is executed for a page request, and saves the changes to the page's or control's view state.
This class implements a dictionary, and you can add items to it or remove items from it as you would any dictionary object. For more information about data collections, such as dictionaries, see Collections and Data Structures.
The following code example demonstrates a composite Label control that has Text and FontSize properties. These properties are saved to and retrieved from view state when the Control::Render method is called on the control.
Available since 1.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.




