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.UI.DomEvent addHandlers Method

Adds a list of DOM event handlers to the DOM element that exposes the events. This member is static and can be invoked without creating an instance of the class.

Syntax

Sys.UI.DomEvent.addHandlers(element, events, handlerOwner);

Term

Definition

element

The DOM element that exposes the events.

events

A dictionary of event handlers.

handlerOwner

(Optional) The object instance that is the context for the delegates that should be created from the handlers.

Exceptions

Exception Type Condition

Error.invalidOperation

(Debug) One of the handlers specified in events is not a function.

Remarks

Use the addHandlers method to add a list of DOM event handlers to the element that exposes the event.

The events parameter takes a comma-separated list of name/value pairs in the format name:value, where name is the name of the DOM event and value is the name of the handler function. If there is more than one name/value pair, the list must be enclosed in braces ({}) to identify it as a single parameter. Multiple name/value pairs are separated with commas. Event names should not include the "on" prefix. For example, specify "click" instead of "onclick".

If handlerOwner is specified, delegates are created for each handler. These delegates are attached to the specified object instance, and the this pointer from the delegate handler will refer to the handlerOwner object.

This method can be accessed through the $addHandlers shortcut method.

Example

The following example shows how to associate event handlers with an element by using the addHandlers method.

cs

<script type="text/javascript">
    Sys.UI.DomEvent.addHandlers($get("Button1"), {click:processEventInfo,mouseover:processEventInfo,mouseout:processEventInfo});

    function processEventInfo(eventElement) {
        var result = '';
        result += eventElement.type;
        $get('Label2').innerHTML = result;
    }
 </script>

vb

<script type="text/javascript">
    Sys.UI.DomEvent.addHandlers($get("Button1"), {click:processEventInfo,mouseover:processEventInfo,mouseout:processEventInfo});

    function processEventInfo(eventElement) {
        var result = '';
        result += eventElement.type;
        $get('Label2').innerHTML = result;
    }
 </script>