Freigeben über


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.

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 Ajax script components. In the Microsoft 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.

// 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);
},

See Also

Reference

Sys.EventHandlerList Class

Other Resources

Language Reference