Control.ViewStateMode Control.ViewStateMode Control.ViewStateMode Control.ViewStateMode Property

定義

取得或設定這個控制項的檢視狀態模式。Gets or sets the view-state mode of this control.

public:
 virtual property System::Web::UI::ViewStateMode ViewStateMode { System::Web::UI::ViewStateMode get(); void set(System::Web::UI::ViewStateMode value); };
[System.Web.UI.Themeable(false)]
public virtual System.Web.UI.ViewStateMode ViewStateMode { get; set; }
member this.ViewStateMode : System.Web.UI.ViewStateMode with get, set
Public Overridable Property ViewStateMode As ViewStateMode

屬性值

這個控制項的檢視狀態模式。The view-state mode of this control.

例外狀況

已嘗試將此屬性設定為不屬於 ViewStateMode 列舉中的值。An attempt was made to set this property to a value that is not in the ViewStateMode enumeration.

備註

您可以使用ViewStateMode屬性來啟用個別控制項的檢視狀態,即使頁面已停用檢視狀態也一樣。You can use the ViewStateMode property to enable view state for an individual control even if view state is disabled for the page. 如需有關檢視狀態和控制項狀態的詳細資訊, EnableViewState請參閱屬性。For more information about view state and control state, see the EnableViewState property.

若要停用頁面的檢視狀態,並為頁面上的特定控制項啟用它,請將EnableViewState頁面的屬性和控制項設定為true,將頁面的ViewStateMode屬性設定為Disabled,並設定ViewStateMode的屬性。控制為EnabledTo disable view state for a page and to enable it for a specific control on the page, set the EnableViewState property of the page and the control to true, set the ViewStateMode property of the page to Disabled, and set the ViewStateMode property of the control to Enabled.

頁面的ViewStateMode屬性預設值為EnabledThe default value of the ViewStateMode property for a page is Enabled. 頁面中 Web 服務器控制項ViewStateMode的屬性預設值為。 InheritThe default value of the ViewStateMode property for a Web server control in a page is Inherit. 因此,如果您未在頁面或控制項層級設定此屬性,則EnableViewState屬性的值會決定檢視狀態行為。As a result, if you do not set this property at either the page or the control level, the value of the EnableViewState property determines view-state behavior.

只有ViewStateMode true當屬性設定為時,頁面或控制項的屬性才會生效。 EnableViewStateThe ViewStateMode property of a page or a control has an effect only if the EnableViewState property is set to true. 如果屬性設定為false,即使ViewStateMode屬性設定為Enabled,也會關閉 view state。 EnableViewStateIf the EnableViewState property is set to false, view state will be turned off even if the ViewStateMode property is set to Enabled.

適用於

另請參閱