HOWTO: Get Web Control Screen Coordinates

D

Dan Sikorsky

How do you get the x,y pixel location of a textbox so that you can position
the Web Date Control popup nearby the associated textbox that will contain
the date selected by the Web Date Control?
 
B

bruce barker

the following client functions work in most browsers:


findPosY = function(obj){
var curtop = 0;
if (document.getElementById || document.all) {
while (obj.offsetParent) {
curtop += obj.offsetTop;
if (typeof(obj.scrollTop) == 'number')
curtop -= obj.scrollTop;
obj = obj.offsetParent;
}
}
else if (document.layers)
curtop += obj.y;
return curtop;
}

findPosX = function(obj) {
var curleft = 0;
if (document.getElementById || document.all) {
while (obj.offsetParent) {
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
}
else if (document.layers)
curleft += obj.x;
return curleft;
}


-- bruse (sqlwork.com)


| How do you get the x,y pixel location of a textbox so that you can
position
| the Web Date Control popup nearby the associated textbox that will contain
| the date selected by the Web Date Control?
|
| --
| Thank you kindly,
| Dan Sikorsky BAB, BScE, MSC
|
|
 
D

Dan Sikorsky

JavaScript just won't do.

The .NET way should be to handle the button click event on the PostBack and
get the screen coordinates of the button. Then add reasonable offsets to the
x,y point and use that as the position to set the popup position.

Having the calendar on a panel, we need to:

pnlCalendar.Style.Item("top") = iTop

pnlCalendar.Style.Item("left") = iLeft



where iTop and iLeft are the aforementioned screen coordinates (needing to
be appropriately computed ... which is the purpose of this posting).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top