Top left coner of html control

Discussion in 'ASP .Net' started by Shimon Sim, Jun 7, 2005.

  1. Shimon Sim

    Shimon Sim Guest

    Is it possible to find top left corner of a control using JavaScript?
    As far as I know it is very easy to do if you use Grid layout while
    designing a page. But if you are using flow layout I didn't find any method
    to find top left corner of a control.

    I see drop down calendars that drop right under control even though I
    designed page in flow layout.
    How do they do it?
    Thank,
    Shimon.
     
    Shimon Sim, Jun 7, 2005
    #1
    1. Advertising

  2. Generally you'd put both controls into a panel, div, or table cell separated
    by a <br> tag.
    Here's a more detailed analysis of your options:
    http://SteveOrr.net/articles/ControlPositioning.aspx

    --
    I hope this helps,
    Steve C. Orr, MCSD, MVP
    http://SteveOrr.net


    "Shimon Sim" <> wrote in message
    news:%...
    > Is it possible to find top left corner of a control using JavaScript?
    > As far as I know it is very easy to do if you use Grid layout while
    > designing a page. But if you are using flow layout I didn't find any
    > method to find top left corner of a control.
    >
    > I see drop down calendars that drop right under control even though I
    > designed page in flow layout.
    > How do they do it?
    > Thank,
    > Shimon.
    >
     
    Steve C. Orr [MVP, MCSD], Jun 8, 2005
    #2
    1. Advertising

  3. Thanks for Steve's informative inputs

    Hi Shimon,

    For html elements in non-absolute layout html page, we need to use
    recursive script function to get their absolute postion on the whole page.
    For example:


    function getAbsoluteLeft(oNode)
    {
    var oCurrentNode = oNode;
    var iLeft = 0;
    while(oNode != null && oCurrentNode.tagName != "BODY" )
    {
    iLeft += oCurrentNode.offsetLeft;
    oCurrentNode=oCurrentNode.offsetParent;
    }

    return iLeft;
    }

    function getAbsoluteTop(oNode)
    {
    var oCurrentNode = oNode;
    var iTop = 0;
    while(oNode != null && oCurrentNode.tagName != "BODY")
    {
    iTop += oCurrentNode.offsetTop;
    oCurrentNode = oCurrentNode.offsetParent;
    }
    return iTop; }

    However, such scripts also depend on the browser's script model support,
    I've test the above functions on IE6 and it works. Hope also helps.

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Jun 8, 2005
    #3
  4. Shimon Sim

    Shimon Sim Guest

    Thank you
    Shimon.
    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Thanks for Steve's informative inputs
    >
    > Hi Shimon,
    >
    > For html elements in non-absolute layout html page, we need to use
    > recursive script function to get their absolute postion on the whole page.
    > For example:
    >
    >
    > function getAbsoluteLeft(oNode)
    > {
    > var oCurrentNode = oNode;
    > var iLeft = 0;
    > while(oNode != null && oCurrentNode.tagName != "BODY" )
    > {
    > iLeft += oCurrentNode.offsetLeft;
    > oCurrentNode=oCurrentNode.offsetParent;
    > }
    >
    > return iLeft;
    > }
    >
    > function getAbsoluteTop(oNode)
    > {
    > var oCurrentNode = oNode;
    > var iTop = 0;
    > while(oNode != null && oCurrentNode.tagName != "BODY")
    > {
    > iTop += oCurrentNode.offsetTop;
    > oCurrentNode = oCurrentNode.offsetParent;
    > }
    > return iTop; }
    >
    > However, such scripts also depend on the browser's script model support,
    > I've test the above functions on IE6 and it works. Hope also helps.
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    >
     
    Shimon Sim, Jun 8, 2005
    #4
  5. You're welcome :)

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Jun 9, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Samuel Rhodes

    Getting Top Left Poition of the control????

    Samuel Rhodes, Apr 13, 2007, in forum: ASP .Net
    Replies:
    7
    Views:
    409
    Sepideh Ghanbari
    Dec 13, 2009
  2. =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=

    Help on table align on left of page vs left hanging indent

    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=, Jul 10, 2007, in forum: XML
    Replies:
    2
    Views:
    1,021
    =?iso-8859-1?q?Jean-Fran=E7ois_Michaud?=
    Jul 16, 2007
  3. Shawn B.

    Top and Left of "Control" Not "WebControl"

    Shawn B., Apr 29, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    132
    Shawn B.
    Apr 29, 2004
  4. Björn Marthen

    How to get the left and top coordinate of custrom control?

    Björn Marthen, Dec 8, 2003, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    161
    Björn Marthen
    Dec 9, 2003
  5. ENathan

    set top and left on web control?

    ENathan, May 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    189
    Mythran
    May 13, 2005
Loading...

Share This Page