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


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

 virtual property bool EnableEventValidation { bool get(); void set(bool value); };
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.


EnableEventValidation屬性設定為true,ASP.NET 驗證控制項的事件來自該控制項所呈現的使用者介面。When 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. 例如,如果清單控制項包含選項、 轉譯頁面時,如果收到回傳要求時指定選項的數字 4 進行編號 1、 2 或 3,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方法,以避免 false 事件驗證錯誤。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屬性,藉由設定enableEventValidation屬性@ Page指示詞或enableEventValidation屬性Web.config 檔案中的項目。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.