Sunday, January 6, 2013

How to get/set a Control’s position on client side?

Microsoft AJAX Library provides a bunch of facilities to manipulate the HTML element on client side, including getting and setting the position of an element.

For example:
To get a Panel's current position on the client side, we can use $common.getLocation(DOM Element) function.
//Get DOM Element with $get() function. 
var el = $get('<%=Panel1.ClientID%>');   
//Get its position.  
var newLocation = $common.getLocation(el);
To set its position:

//Create the new position.
var newLocation = new Sys.UI.Point(x-position,y-position);
//Move the Panel to the destination.
$common.setLocation(Panel, newLocation); 

No comments:

Post a Comment