3 out of 4 rated this helpful - Rate this topic

PageStatePersister.ControlState Property

Note: This property is new in the .NET Framework version 2.0.

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.

Namespace: System.Web.UI
Assembly: System.Web (in system.web.dll)

public Object ControlState { get; set; }
/** @property */
public Object get_ControlState ()

/** @property */
public void set_ControlState (Object value)

public function get ControlState () : Object

public function set ControlState (value : Object)

Property Value

An object that contains view state data.

Control state is an object comprised of critical view state data that Web server controls need to function, and is contained in a separate object from normal view state information. Control state data is not affected when view state is disabled at the Page level, but requires extra implementation steps to use. For more information on using the ViewState property 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 ControlState property. In this example, the ControlState property has been assigned to the Second field of a Pair object, and serialized using the ObjectStateFormatter class. When the Load method is called, the ObjectStateFormatter class is used to deserialize view state and control state information, and the ControlState property is initialized from the resulting Pair object's Second field. This code example is part of a larger example provided for the PageStatePersister class.

//
// Load ViewState and ControlState.
//
public override void Load()
{
    Stream stateStream = GetSecureStream();

    // Read the state string, using the StateFormatter.
    StreamReader reader = new StreamReader(stateStream);

    IStateFormatter formatter = this.StateFormatter;
    string fileContents = reader.ReadToEnd();

    // Deserilize returns the Pair object that is serialized in
    // the Save method.
    Pair statePair = (Pair)formatter.Deserialize(fileContents);

    ViewState = statePair.First;
    ControlState = statePair.Second;
    reader.Close();
    stateStream.Close();
}

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ