Control.LoadViewState(Object) Method


从用 SaveViewState() 方法保存的上一个页面请求还原视图状态信息。Restores view-state information from a previous page request that was saved by the SaveViewState() method.

 virtual void LoadViewState(System::Object ^ savedState);
protected virtual void LoadViewState (object savedState);
abstract member LoadViewState : obj -> unit
override this.LoadViewState : obj -> unit
Protected Overridable Sub LoadViewState (savedState As Object)



表示要还原的控件状态的 ObjectAn Object that represents the control state to be restored.


下面的示例将重写自定义 ASP.NET 服务器控件的 LoadViewState 方法。The following example overrides the LoadViewState method for a custom ASP.NET server control. 它将创建一个 Object 数组以包含传入 savedState 参数的视图状态信息,然后调用该数组的第一个索引位置的 LoadViewState 方法的基实现。It creates an Object array to contain the view state information passed in the savedState parameter, and then calls the base implementation of the LoadViewState method for the first index location of the array. 它将存储在接下来两个索引位置的值分配给分别为 UserTextPasswordText的变量。It assigns the values stored at the next two index locations to variables named UserText and PasswordText, respectively.

protected override void LoadViewState(object savedState) 
   if (savedState != null)
      // Load State from the array of objects that was saved at ;
      // SavedViewState.
      object[] myState = (object[])savedState;
      if (myState[0] != null)
      if (myState[1] != null)
         UserText = (string)myState[1];
      if (myState[2] != null)
         PasswordText = (string)myState[2];
Protected Overrides Sub LoadViewState(savedState As Object)
   If Not (savedState Is Nothing) Then
      ' Load State from the array of objects that was saved at ;
      ' SavedViewState.
      Dim myState As Object() = CType(savedState, Object())
      If Not (myState(0) Is Nothing) Then
      End If
      If Not (myState(1) Is Nothing) Then
         UserText = CStr(myState(1))
      End If
      If Not (myState(2) Is Nothing) Then
         PasswordText = CStr(myState(2))
      End If
   End If
End Sub


此方法主要由 .NET Framework 基础结构使用,不应在代码中直接使用。This method is used primarily by the .NET Framework infrastructure and is not intended to be used directly from your code. 不过,控件开发人员可以重写此方法,以指定自定义服务器控件如何还原其视图状态。However, control developers can override this method to specify how a custom server control restores its view state. 有关详细信息,请参阅ASP.NET 状态管理概述For more information, see ASP.NET State Management Overview.

Applies to

See also