Parameter.ViewState 屬性


取得狀態資訊的字典,允許您在相同頁面的多個要求之間,儲存和還原 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.

 property System::Web::UI::StateBag ^ ViewState { System::Web::UI::StateBag ^ get(); };
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.



下列程式碼範例示範如何在擴充類別的類別中,使用 view-state 物件來儲存參數物件狀態 ParameterThe following code example demonstrates how to use the view-state object to store parameter object state in a class that extends the Parameter class. 這個程式碼範例是針對類別總覽提供的較大範例的一部分 ParameterThis 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
      Return ViewState("Value")
   End Get
      ViewState("Value") = value
   End Set
End Property


參數的檢視狀態會累積其所有屬性值。A parameter's view state is the accumulation of all its property values. 若要在 HTTP 要求之間保留這些值,ASP.NET server 控制項會使用這個屬性(這是類別的實例 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. 然後,這些值會在處理後續要求時,以變數形式傳遞至 HTML hidden 輸入元素。The values are then passed as a variable to an HTML hidden input element when subsequent requests are processed. 預設會為所有伺服器控制項啟用 [View state]。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.