请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
先前版本
System.Web.UI
 ControlState 属性
全部折叠/全部展开 全部折叠
此页面仅适用于
Microsoft Visual Studio 2005/.NET Framework 2.0

同时提供下列产品的其他版本:
.NET Framework 类库
PageStatePersister.ControlState 属性

注意:此属性在 .NET Framework 2.0 版中是新增的。

获取或设置一个对象,该对象表示当前 Page 对象包含的控件用于跨 Web 服务器的 HTTP 请求保留的数据。

命名空间:System.Web.UI
程序集:System.Web(在 system.web.dll 中)

Visual Basic(声明)
Public Property ControlState As Object
Visual Basic(用法)
Dim instance As PageStatePersister
Dim value As Object

value = instance.ControlState

instance.ControlState = value
C#
public Object ControlState { get; set; }
C++
public:
property Object^ ControlState {
    Object^ get ();
    void set (Object^ value);
}
J#
/** @property */
public Object get_ControlState ()

/** @property */
public void set_ControlState (Object value)
JScript
public function get ControlState () : Object

public function set ControlState (value : Object)

属性值

包含视图状态数据的对象。

控件状态是一个包含 Web 服务器控件正常工作所需要的关键视图状态数据的对象,并且它包含在一个单独的对象(与包含普通视图状态信息的对象不同)中。在 Page 级别禁用视图状态时,控件状态数据不会受到影响,但是需要额外的实现步骤才能使用。有关在开发控件时使用 ViewState 属性和控件状态的更多信息,请参见 开发自定义 ASP.NET 服务器控件

下面的代码示例演示一个从 PageStatePersister 类派生的类如何初始化 ControlState 属性。此示例将 ControlState 属性指派给 Pair 对象的 Second 字段,并使用 ObjectStateFormatter 类对该属性进行序列化。调用 Load 方法时,使用 ObjectStateFormatter 类对视图状态和控件状态信息进行反序列化,并使用所得 Pair 对象的 Second 字段初始化 ControlState 属性。此代码示例摘自一个为 PageStatePersister 类提供的更大的示例。

Visual Basic
'
' 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
C#
//
// 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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

.NET Framework

受以下版本支持:2.0
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利 | 商标 | 隐私权声明
Page view tracker