ICallbackEventHandler Interface


用于指示控件可以作为服务器上的回调事件的目标。Used to indicate that a control can be the target of a callback event on the server.

public interface class ICallbackEventHandler
public interface ICallbackEventHandler
type ICallbackEventHandler = interface
Public Interface ICallbackEventHandler


为需要接收回叫事件的任何自定义控件实现 ICallbackEventHandler 接口。Implement the ICallbackEventHandler interface for any custom control that needs to receive callback events. 有关详细信息,请参阅实现无回发的客户端回调For more information, see Implementing Client Callbacks Without Postbacks.

实现 ICallbackEventHandler 接口的控件的示例包括 GridViewDetailsViewTreeView 控件。Examples of controls that implement the ICallbackEventHandler interface include the GridView, DetailsView, and TreeView controls. 当回调事件面向实现 ICallbackEventHandler 接口的控件时,将调用 RaiseCallbackEvent 方法来处理事件,并将事件自变量作为参数传递,并且 GetCallbackResult 方法返回回调的结果。When a callback event targets a control that implements the ICallbackEventHandler interface, the RaiseCallbackEvent method is called to handle the event, passing the event argument as a parameter and the GetCallbackResult method returns the result of the callback.

在回调过程中从数据源控件检索数据的控件可以同步或异步执行此操作。Controls that retrieve data from a data source control during callback can do so synchronously or asynchronously. ASP.NET 控件,如 GridViewDetailsViewTreeView 都同步实现。ASP.NET controls like GridView, DetailsView, and TreeView are implemented synchronously. 同步回调不会阻止用户在浏览器中工作。Synchronous callbacks do not prevent the user from working in the browser. 在同步模式下,一次只能执行一个回调,并优先处理最后一个回调。In synchronous mode, only one callback at a time can execute, with the last callback taking precedence. 实现 Web 控件以支持异步行为时,可以同时引发多个回调。When a Web control is implemented to support asynchronous behavior, multiple callbacks can be raised simultaneously. 有关异步编程的详细信息,请参阅基于事件的异步模式(EAP)For details on asynchronous programming, see Event-based Asynchronous Pattern (EAP).

您可以指定是否验证源自实现 ICallbackEventHandler 接口的控件所呈现的用户界面的回调事件。You can specify whether callback events originating from the user interface rendered by a control implementing the ICallbackEventHandler interface are validated. 事件验证是一种很好的安全做法。Validation of events is a good security practice. 但出于性能原因,你可以禁用它。However, for performance reasons you can disable it. 若要控制是否对回调事件执行事件验证,请设置@ Page指令的 enableEventValidation 属性或 web.config 文件的pages 元素(ASP.NET 设置架构)enableEventValidation 属性。To control whether event validation is performed on callback events, set the enableEventValidation attribute of the @ Page directive or the enableEventValidation attribute of the pages Element (ASP.NET Settings Schema) of the Web.config file. 如果在代码中设置 EnableEventValidation 属性,请在 "页面处理" 的 "Page_Init" 阶段设置该属性。If you set the EnableEventValidation property in code, set it in the Page_Init phase of page processing. 若要详细了解事件验证的安全优势及其性能成本,请参阅ASP.NET 性能概述For more information on balancing the security benefit of event validation with its performance cost, see ASP.NET Performance Overview.



返回以控件为目标的回调事件的结果。Returns the results of a callback event that targets a control.


处理以控件为目标的回调事件。Processes a callback event that targets a control.

Applies to

See also