Tuesday, February 24, 2009

How to Get Location Of any Control using Sys.UI.DomElement.getLocation class in Javascript

Hi
Today I want to share a small but very good javascript that is used to get the Location of any control by using the Control using Sys.UI.DomElement.getLocation Class..



Step 1:)
Write the HTML of any control , here suppose we are using the Button .
< id="Btn" text ="FindLocation" onclientclick= "return findLoc(this);" runat="server">

Step 2:)

Write the javascript like below...

function findLoc(ctrlBtn)
{
var location = Sys.UI.DomElement.getLocation(ctrlBtn);
alert(location.x);
alert(location.y);
alert(ctrlBtn.offsetWidth);
alert(ctrlBtn.offsetHeight)
return false;
}

Thanks:
Sanjeev Kumar

No comments: