ICallbackEventHandler 接口

定义

用于指示控件可以作为服务器上的回调事件的目标。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
派生

注解

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

实现ICallbackEventHandler接口的控件的示例GridView包括、 DetailsViewTreeView控件。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 控件 ( GridViewDetailsView、和TreeView ) 是同步实现的。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. 若要控制是否对回调事件执行事件验证, 请设置enableEventValidation web.config 文件的@ Page指令或enableEventValidation pages 元素 (ASP.NET Settings Schema)的属性。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.

方法

GetCallbackResult()

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

RaiseCallbackEvent(String)

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

适用于

另请参阅