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,也会关闭视图状态。 EnableViewStateIf the EnableViewState property is set to false, view state will be turned off even if the ViewStateMode property is set to Enabled.

适用于

另请参阅