Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.

 

 

 

 

 

 

 

Sys.EventHandlerList.addHandler Method

Attaches a handler to an event in an EventHandlerList instance and adds the event to the list if it is not already present.

Syntax

var e = new Sys.EventHandlerList();
e.addHandler(id, handler);

Arguments

id

A string that specifies the event.

handler

The name of the method to handle the event.

Remarks

Use the addHandler method to programmatically attach handlers to events in Microsoft ASP.NET AJAX script components. In the ASP.NET AJAX component event model, client events reside in an EventHandlerList object. Handlers are created and assigned to the event by using the addHandler method. You then raise the events by calling the method that is returned by the getHandler method.

If the id value that you pass to addHandler is already in the EventHandlerList instance, the method specified by handler is added to any handlers already associated with the event. Otherwise, a new event that has the specified ID and handler is added to the EventHandlerList object.

Example

The following example shows how to call the addHandler and removeHandler methods in a custom control. This is part of a larger example found in the EventHandlerList class overview.

cs

// Bind and unbind to click event.
add_click: function(handler) {
    this.get_events().addHandler('click', handler);
},
remove_click: function(handler) {
    this.get_events().removeHandler('click', handler);
},