Control.EnableViewState プロパティ
定義
要求元クライアントに対して、サーバー コントロールがそのビュー状態と、そこに含まれる任意の子のコントロールのビュー状態を保持するかどうかを示す値を取得または設定します。Gets or sets a value indicating whether the server control persists its view state, and the view state of any child controls it contains, to the requesting client.
public:
virtual property bool EnableViewState { bool get(); void set(bool value); };
public virtual bool EnableViewState { get; set; }
[System.Web.UI.Themeable(false)]
public virtual bool EnableViewState { get; set; }
member this.EnableViewState : bool with get, set
[<System.Web.UI.Themeable(false)>]
member this.EnableViewState : bool with get, set
Public Overridable Property EnableViewState As Boolean
プロパティ値
サーバー コントロールがビュー状態を保持する場合は true
、それ以外の場合は false
。true
if the server control maintains its view state; otherwise false
. 既定値は、true
です。The default is true
.
- 属性
例
次の例では、 EnableViewState プロパティをに設定し false
ます。The following example sets the EnableViewState property to false
.
void Page_Load(object sender, System.EventArgs e)
{
DataBind();
// Set EnableViewState to false to disable saving of view state
// information.
myControl.EnableViewState = false;
if (!IsPostBack)
display.Enabled = false;
}
Sub Page_Load(sender As Object, e As System.EventArgs)
DataBind()
' Set EnableViewState to false to disable saving of view state
' information.
myControl.EnableViewState = False
If Not IsPostBack Then
display.Enabled = False
End If
End Sub
注釈
ビューステートを使用すると、サーバーコントロールは HTTP 要求間で状態を維持できます。View state enables a server control to maintain its state across HTTP requests. 次のすべての条件が満たされている場合は、コントロールのビューステートが有効になります。View state for a control is enabled if all of the following conditions are met:
EnableViewStateページのプロパティがに設定されて
true
います。The EnableViewState property for the page is set totrue
.EnableViewStateコントロールのプロパティがに設定されて
true
います。The EnableViewState property for the control is set totrue
.ViewStateModeコントロールのプロパティがに設定されている Enabled か、または設定を継承してい Enabled ます。The ViewStateMode property for the control is set to Enabled or inherits the Enabled setting.
詳細については、ViewStateMode プロパティを参照してください。For more information, see the ViewStateMode property.
サーバーコントロールのビューステートは、すべてのプロパティ値を累積したものです。A server control's view state is the accumulation of all its property values. これらの値を HTTP 要求間で保持するために、ASP.NET はクラスのインスタンスを使用し StateBag てプロパティ値を格納します。In order to preserve these values across HTTP requests, ASP.NET uses an instance of the StateBag class to store the property values. 値は、後続の要求が処理されるときに、非表示フィールドに変数として渡されます。The values are then passed as a variable to a hidden field when subsequent requests are processed. ビューステートの詳細については、「 ASP.NET View state の概要」を参照してください。For more information about view state, see ASP.NET View State Overview.
ビューステートを無効にするのが適切な場合もあります。特に、アプリケーションのパフォーマンスを向上させるためです。There are times when it is appropriate to disable view state, particularly to improve application performance. たとえば、データベース要求をサーバーコントロールに読み込んでいる場合は、このプロパティをに設定 false
します。For example, if you are loading a database request into a server control, set this property to false
. そうしないと、データベースクエリによってのみ上書きされるサーバーコントロールへのビューステートの読み込みが、プロセッサ時間の無駄になります。If you do not, processor time will be wasted loading view state into the server control that will only be overridden by the database query. がの場合は EnableViewState false
、コントロールの状態を使用して、コントロールに固有のプロパティ情報を永続化することができます。また、"ビューステート" プロパティのように無効にすることはできません。If EnableViewState is false
, you can use the control state to persist property information that is specific to a control and cannot be turned off like the view state property. コントロールの状態とビューステートの違いの詳細については、「コントロールの状態とビューステートの例」を参照してください。For more information on the difference between control state and view state, see Control State vs. View State Example.
ASP.NET ページのビューステートを宣言によって有効または無効にする方法の詳細については、「 @ page」を参照してください。For information about how to enable or disable view state declaratively for an ASP.NET page, see @ Page.