Gets or sets an object that represents the data that controls contained by the current Page object use to persist across HTTP requests to the Web server.
Assembly: System.Web (in System.Web.dll)
View state is a dictionary of state data that Web server controls need to function and render themselves. Control developers typically access the view state object using the ViewState property. View state is affected when view state is disabled at the Page level, and as a result controls might not behave correctly in these scenarios. For more information on using ViewState and control state when developing controls, see Developing Custom ASP.NET Server Controls.
The following code example demonstrates how a class that derives from the PageStatePersister class initializes the property. In this example, the property has been assigned to the First field of a Pair object, and serialized using the ObjectStateFormatter object, which is an instance of the IStateFormatter interface. When the Load method is called, the ObjectStateFormatter interface is used to deserialize view state information, and the property is initialized from the resulting Pair object's First field. This code example is part of a larger example provided for the PageStatePersister class.
' ' Load ViewState and ControlState. ' Public Overrides Sub Load() Dim stateStream As Stream stateStream = GetSecureStream() ' Read the state string, using the StateFormatter. Dim reader As New StreamReader(stateStream) Dim serializedStatePair As String serializedStatePair = reader.ReadToEnd Dim statePair As Pair Dim formatter As IStateFormatter formatter = Me.StateFormatter ' Deserilize returns the Pair object that is serialized in ' the Save method. statePair = CType(formatter.Deserialize(serializedStatePair), Pair) ViewState = statePair.First ControlState = statePair.Second reader.Close() stateStream.Close() End Sub ' Load
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.