Referencing a control in Javascript

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Referencing a control in Javascript

    Hi all,

    In my code-behind, I validate some controls and if a particular control has
    a problem, I not only send an alert down to the client via
    Page.RegisterStartupScript but I'd like to set the focus of the control. now
    the control in question is embedded into a user control which is, in turn,
    embedded into a user control which, in turn, is embedded onto a web form.

    The Javascript does not work if I when I refernce the control with it's ID.
    I checked the client source and saw it was renamed to
    '_ctl2_UCIngDetail_lstUnits2'. Now when I changed the Javascript to
    'document.frmMain._ctl2_UCIngDetail_lstUnits2.focu s();', this worked. but
    isn't this going to break if controls are added to the usercontrol?

    What is the correct way to solve this dilemma?

    Regards
    John.


    John Guest

  2. Similar Questions and Discussions

    1. Referencing a parent control from a child?
      I have two UserControls I'd like to have talk to each other. One of them is contained within the other, in a parent/child relationship. The child...
    2. output text in control location; calling control javascript from page javascript
      Hi; If you don't know, I'm just learning javascript and aspnet, but I have a pretty good grounding in windows programming. I'm trying to build a...
    3. javascript: a method for referencing model by nam
      this is kind of bassackwards, but it will work. i aint found a way to reference a model directly by name (yet), and since a model's index number is...
    4. Referencing Control Operators
      Greetings. Is it possible to reference a control operator? For example, I'd like to take this code: sub getFieldFromAllRecords { my...
    5. Referencing a TextBox control in Javascript from DataList ItemTemplate
      I have a calendar control which pops up as a new window when i click on my textbox. The calendar control returns a Javascript function whereby...
  3. #2

    Default Re: Referencing a control in Javascript

    You will need to use the "ClientID" property of the control to reference it
    properly.


    "John" <a@b.com> wrote in message
    news:#U#wyG2QDHA.2592@TK2MSFTNGP10.phx.gbl...
    > Hi all,
    >
    > In my code-behind, I validate some controls and if a particular control
    has
    > a problem, I not only send an alert down to the client via
    > Page.RegisterStartupScript but I'd like to set the focus of the control.
    now
    > the control in question is embedded into a user control which is, in turn,
    > embedded into a user control which, in turn, is embedded onto a web form.
    >
    > The Javascript does not work if I when I refernce the control with it's
    ID.
    > I checked the client source and saw it was renamed to
    > '_ctl2_UCIngDetail_lstUnits2'. Now when I changed the Javascript to
    > 'document.frmMain._ctl2_UCIngDetail_lstUnits2.focu s();', this worked. but
    > isn't this going to break if controls are added to the usercontrol?
    >
    > What is the correct way to solve this dilemma?
    >
    > Regards
    > John.
    >
    >

    PJ Lee Guest

  4. #3

    Default Re: Referencing a control in Javascript

    js ="<script ...>" & txtBox.ClientID & ".focus();</scirpt>"


    "John" <a@b.com> wrote in message
    news:#U#wyG2QDHA.2592@TK2MSFTNGP10.phx.gbl...
    > Hi all,
    >
    > In my code-behind, I validate some controls and if a particular control
    has
    > a problem, I not only send an alert down to the client via
    > Page.RegisterStartupScript but I'd like to set the focus of the control.
    now
    > the control in question is embedded into a user control which is, in turn,
    > embedded into a user control which, in turn, is embedded onto a web form.
    >
    > The Javascript does not work if I when I refernce the control with it's
    ID.
    > I checked the client source and saw it was renamed to
    > '_ctl2_UCIngDetail_lstUnits2'. Now when I changed the Javascript to
    > 'document.frmMain._ctl2_UCIngDetail_lstUnits2.focu s();', this worked. but
    > isn't this going to break if controls are added to the usercontrol?
    >
    > What is the correct way to solve this dilemma?
    >
    > Regards
    > John.
    >
    >

    David Waz... Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139