共用方式為


Control.LoadViewState(Object) 方法

定義

SaveViewState() 方法所儲存的先前頁面要求來還原檢視狀態資訊。

protected:
 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)

參數

savedState
Object

Object,代表所要還原的控制項狀態。

範例

下列範例會 LoadViewState 覆寫自定義 ASP.NET 伺服器控制件的方法。 它會建立數位,以包含傳入參數的savedState檢視狀態資訊,然後針對陣列的第一個Object索引位置呼叫 方法的基底實LoadViewState作。 它會將儲存在下兩個索引位置的值分別指派給名為 UserTextPasswordText的變數。

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)
         base.LoadViewState(myState[0]);
      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
         MyBase.LoadViewState(myState(0))
      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 基礎結構使用,不適合直接從您的程序代碼使用。 不過,控件開發人員可以覆寫這個方法,以指定自定義伺服器控件如何還原其檢視狀態。 如需詳細資訊,請參閱 ASP.NET 狀態管理概觀

適用於

另請參閱