Parameter.ViewState Parameter.ViewState Parameter.ViewState Parameter.ViewState Property

定義

取得狀態資訊的字典,允許您在相同頁面的多個要求之間,儲存和還原 Parameter 物件的檢視狀態。Gets a dictionary of state information that allows you to save and restore the view state of a Parameter object across multiple requests for the same page.

protected:
 property System::Web::UI::StateBag ^ ViewState { System::Web::UI::StateBag ^ get(); };
[System.ComponentModel.Browsable(false)]
protected System.Web.UI.StateBag ViewState { get; }
member this.ViewState : System.Web.UI.StateBag
Protected ReadOnly Property ViewState As StateBag

屬性值

StateBag 的執行個體,包含 Parameter 物件的檢視狀態資訊。An instance of StateBag that contains the Parameter object's view-state information.

範例

下列程式碼範例示範如何使用檢視狀態物件,將參數物件狀態儲存在擴充Parameter類別的類別中。The following code example demonstrates how to use the view-state object to store parameter object state in a class that extends the Parameter class. 這個程式碼範例是針對Parameter類別總覽提供之較大範例的一部分。This code example is part of a larger example provided for the Parameter class overview.

// The DataValue can be any arbitrary object and is stored in ViewState.
public object DataValue {
  get {
    return ViewState["Value"];
  }
  set {
    ViewState["Value"] = value;
  }
}
' The DataValue can be any arbitrary object and is stored in ViewState.
Public Property DataValue() As Object
   Get
      Return ViewState("Value")
   End Get
   Set
      ViewState("Value") = value
   End Set
End Property

備註

參數的 view state 是其所有屬性值的累積。A parameter's view state is the accumulation of all its property values. 為了跨 HTTP 要求保留這些值,ASP.NET 伺服器控制項會使用這個屬性(也就是StateBag類別的實例)來儲存屬性值。To preserve these values across HTTP requests, ASP.NET server controls use this property, which is an instance of the StateBag class, to store the property values. 然後,在處理後續要求時,這些值會hidden當做變數傳遞至 HTML 輸入元素。The values are then passed as a variable to an HTML hidden input element when subsequent requests are processed. 預設會針對所有伺服器控制項啟用 [檢視狀態]。View state is enabled for all server controls by default.

如需有關字典及其使用方式的詳細資訊,請參閱集合和資料結構For more information about dictionaries and how to use them, see Collections and Data Structures.

適用於

另請參閱