How to: Implement Callbacks in ASP.NET Web Pages

In a client callback, a client script function sends a request to the ASP.NET Web page, which then runs an abbreviated version of its normal life cycle to process the callback. To ensure that callback events originate from the expected user interface (UI), you can validate callbacks. In callback validation, you register an event for validation during the Web page rendering and then validate the event during the callback. For an overview of callbacks, see Implementing Client Callbacks Programmatically Without Postbacks in ASP.NET Web Pages.

To implement the ICallBackEventHandler interface

  1. For a single-file page or user control, implement the ICallbackEventHandler interface using an @ Implements directive in the page, as shown in the following example.

    <%@ Page Language="C#" %>
    <%@ Implements Interface="System.Web.UI.ICallbackEventHandler" %>

    If you are using a code-behind page model, implement the ICallbackEventHandler interface for your partial class.

  2. Implement the RaiseCallbackEvent method of the ICallbackEventHandler interface. The RaiseCallbackEvent method takes a single argument that represents the event arguments, as shown in the following example.

    public void RaiseCallbackEvent(String eventArgument)
  3. Implement the GetCallbackResult method of the ICallbackEventHandler interface. The GetCallbackResult method takes no arguments and returns a string that represents the result of the callback. In the following example, a string called returnValue is returned.

    public String GetCallbackResult()
        return returnValue;

To register the callback for event validation

  • Override the Render method of the Page class and use the RegisterForEventValidation method of the ClientScriptManager class to register an event for validation. You can get a reference to the ClientScriptManager class by using the ClientScript property of the Page class. In the following example, a callback named Callback1 is registered for event validation.

    protected override void Render(HtmlTextWriter writer)

To validate the callback and return the callback result

Community Additions