Manages the view state of ASP.NET server controls, including pages. This class cannot be inherited.
Assembly: System.Web (in System.Web.dll)
Thetype exposes the following members.
|Add||Adds a new StateItem object to the object. If the item already exists in the object, this method updates the value of the item.|
|Clear||Removes all items from the current object.|
|Equals(Object)||Determines whether the specified Object is equal to the current Object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetEnumerator||Returns an enumerator that iterates over all the key/value pairs of the StateItem objects stored in the object.|
|GetHashCode||Serves as a hash function for a particular type. (Inherited from Object.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|IsItemDirty||Checks a StateItem object stored in the object to evaluate whether it has been modified since the call to Control.TrackViewState.|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|Remove||Removes the specified key/value pair from the object.|
|SetDirty||Sets the state of the object as well as the Dirty property of each of the StateItem objects contained by it.|
|SetItemDirty||Sets the Dirty property for the specified StateItem object in the object.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
|AsParallel||Enables parallelization of a query. (Defined by ParallelEnumerable.)|
|AsQueryable||Converts an IEnumerable to an IQueryable. (Defined by Queryable.)|
|Cast(Of TResult)||Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)|
|OfType(Of TResult)||Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)|
|ICollection.CopyTo||For a description of this member, see ICollection.CopyTo.|
|ICollection.IsSynchronized||For a description of this member, see ICollection.IsSynchronized.|
|ICollection.SyncRoot||For a description of this member, see ICollection.SyncRoot.|
|IDictionary.Add||For a description of this member, see IDictionary.Add.|
|IDictionary.Contains||For a description of this member, see IDictionary.Contains.|
|IDictionary.IsFixedSize||For a description of this member, see IDictionary.IsFixedSize.|
|IDictionary.IsReadOnly||For a description of this member, see IDictionary.IsReadOnly.|
|IDictionary.Item||For a description of this member, see IDictionary.Item.|
|IDictionary.Remove||For a description of this member, see Remove.|
|IEnumerable.GetEnumerator||For a description of this member, see IEnumerable.GetEnumerator.|
|IStateManager.IsTrackingViewState||Gets a value indicating whether state changes are being tracked.|
|IStateManager.LoadViewState||Restores the previously saved view state of the object.|
|IStateManager.SaveViewState||Saves the changes to the object since the time the page was posted back to the server.|
|IStateManager.TrackViewState||Causes the object to track changes to its state so that it can be persisted across requests.|
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 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.
' This control renders values stored in view state for Text and FontSize properties. Imports System Imports System.Web Imports System.Web.UI Namespace ViewStateControlSamples Public Class CustomLabel : Inherits Control Private Const defaultFontSize As Integer = 3 ' Add property values to view state with set; ' retrieve them from view state with get. Public Property [Text]() As String Get Dim o As Object = ViewState("Text") If (IsNothing(o)) Then Return String.Empty Else Return CStr(o) End If End Get Set(ByVal value As String) ViewState("Text") = value End Set End Property Public Property FontSize() As Integer Get Dim o As Object = ViewState("FontSize") If (IsNothing(o)) Then Return defaultFontSize Else Return CInt(ViewState("FontSize")) End If End Get Set(ByVal value As Integer) ViewState("FontSize") = value End Set End Property <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _ Protected Overrides Sub Render(ByVal Output As HtmlTextWriter) Output.Write("<font size=" & Me.FontSize & ">" & Me.Text & "</font>") End Sub End Class End Namespace
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.