How to get the position of ASP.NET textbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jmarsh111
    New Member
    • Sep 2007
    • 1

    How to get the position of ASP.NET textbox

    Does anyone know how to get the top and left positions of an ASP.NET WebControl..? I have an aspx page with controls that when clicked on enters a javascript function that looks like:
    [CODE=javascript]
    function ShowPosition(oC trl)
    {


    var ctrl = document.getEle mentById("ctrl_ id");

    var top = ctrl.style.top;
    var left = ctrl.style.left ;

    alert(top + ", " + left);

    }
    [/CODE]

    The asp.net tag that calls the javascript function looks like:
    [code=html]
    <asp:textbox id="ctrl_id" runat="server" onclick="ShowPo sition(this);"> </asp:textbox>[/code]

    But this doesn't work. Please help.
    Last edited by pbmods; Sep 5 '07, 10:19 PM. Reason: Added CODE tags.
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    this would need a style position absolute

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, J Marsh. Welcome to TSDN!

      Hopefully, this article will have all the info you need.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Originally posted by jmarsh111
        The asp.net tag that calls the javascript function looks like:
        [code=html]
        <asp:textbox id="ctrl_id" runat="server" onclick="ShowPo sition(this);"> </asp:textbox>[/code]
        One question, if you're passing a reference to the object (this), why not make use of it? Replace ctrl with oCtrl in your Javascript.

        Comment

        Working...