Ajax Shortcuts

The Ajax ScriptManager has a set of client side reference function, which can be used with javascript.

1. $get("elementID")

Method that gets the reference to the specified Control id.This is equivalent to the method document.getElementById("elementId"), it returns the control object.

$get("elementid").value = someValue;
var someVariable = $get("elementid").value;
//Direct Method
Sys.UI.DomEvent.get("elementid").value = someValue;
var someVariable = Sys.UI.DomEvent.get("elementid").value;

2. $find("elementID",parent)

Finds the control within the page or within the specified parent. This is more similar to server side Find Control method, the parent parameter is optional, if provided, the search is specified to that parent control only. it returns control object if found else returns null.

var o = $find("elementID", mydiv);
//Direct Method
var obj = Sys.UI.DomEvent.find("elementID", mydiv);

3. $addHandler(element, eventName, handler);

Method to assign a handler function to event of a specified control. The eventName parameter should not include the "on" prefix. For example, specify "click" instead of "onclick".

//Direct Method

4. $removeHandler(element, eventName, handler);
Method to remove a existing handler function to event of a specified control.

//Direct Method

No comments:

Post a Comment