Page.EnableEventValidation Page.EnableEventValidation Page.EnableEventValidation Page.EnableEventValidation Property

定義

取得或設定值,指出頁面是否驗證回傳和回呼事件。Gets or sets a value indicating whether the page validates postback and callback events.

public:
 virtual property bool EnableEventValidation { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(false)]
public virtual bool EnableEventValidation { get; set; }
member this.EnableEventValidation : bool with get, set
Public Overridable Property EnableEventValidation As Boolean

屬性值

如果網頁會驗證回傳和回呼事件,則為 true,否則為 false。預設為 truetrue if the page validates postback and callback events; otherwise, false.The default is true.

例外狀況

EnableEventValidation 屬性已在頁面初始化之後設定。The EnableEventValidation property was set after the page was initialized.

備註

當屬性設定為true時, ASP.NET 會驗證控制項事件是否源自該控制項所呈現的使用者介面。 EnableEventValidationWhen the EnableEventValidation property is set to true, ASP.NET validates that a control event originated from the user interface that was rendered by that control. 控制項會在呈現期間註冊其事件, 然後在回傳或回呼處理期間驗證事件。A control registers its events during rendering and then validates the events during postback or callback handling. 例如, 如果清單控制項在轉譯頁面時包含編號為1、2或3的選項, 而且如果收到指定選項編號4的回傳要求, 則 ASP.NET 會引發例外狀況。For example, if a list control includes options numbered 1, 2, or 3 when the page is rendered, and if a postback request is received specifying option number 4, ASP.NET raises an exception. ASP.NET 中的所有事件導向控制項預設都會使用這項功能。All event-driven controls in ASP.NET use this feature by default.

如果您撰寫的用戶端腳本會在執行時間變更用戶端中的控制項, 您可能必須使用RegisterForEventValidation方法, 以避免發生錯誤的事件驗證錯誤。If you write client script that changes a control in the client at run time, you might have to use the RegisterForEventValidation method in order to avoid false event validation errors.

重要

這項功能可降低未經授權或惡意回傳要求和回呼的風險。This feature reduces the risk of unauthorized or malicious postback requests and callbacks. 強烈建議您不要停用事件驗證。It is strongly recommended that you do not disable event validation.

您可以設定EnableEventValidation @ Page指示enableEventValidationenableEventValidation的屬性, 或 web.config 檔案中pages元素的屬性, 以設定屬性。You set the EnableEventValidation property by setting the enableEventValidation attribute of the @ Page directive or the enableEventValidation attribute of the pages element in the Web.config file. 如果您在程式碼中設定這個屬性, 就必須在頁面初始化之前設定它。If you set this property in code, you must set it before the page is initialized.

適用於

另請參閱