Re: Dynamically create controls with non-hierarchical IDs

Discussion in 'ASP .Net' started by John Saunders, Jul 15, 2004.

  1. "Simon Wallis" <> wrote in message
    news:...
    > I have a PlaceHolder inside a repeater so that I can dynamically add

    controls to my page. Each time the repeater.ItemDataBound event fires I
    create a Label and add it to the PlaceHolder.
    >
    > Now, when I create this Label, I set the ID to have the dynamic value:
    > "lblSubTotal_" + strCurrencyCode;
    >
    > ASP.NET will turn this Label into a [span] tag in the resulting HTML

    output, and I want to manipulate this tag using Javascript. In JS I want to
    get a reference to the tag via its ID value. For example:
    > objCurrencySubtotal = document.getElementById("lblSubTotal_USD");
    >
    > The problem is that when ASP.NET creates the [span] tag, it modifies the

    ID value by prepending a whole bunch of hierarchically-qualified info. For
    example, this is the span tag I end up with in the HTML output:
    > <span

    id="pbdTemplate__PageTemplate_innerHolder_ctrlBalances_rptrAggregateTotals__
    ctl1_lblSubTotal_USD">
    >
    > I cannot find this easily using Javascript. Does anyone know how to stop

    ASP.NET from prepending all that hierchical info and force it to use the ID
    value I myself assign to the control?

    Simon,

    Another solution is to pass the ID to the JavaScript code. For instance, if
    you need to call your JavaScript on a Click event:

    lblClickMe.Attributes.Add("onclick",
    string.Format("MyJSFunction('{0}');", myLabel.UniqueID));

    MyJSFunction will then be able to get the element using getElementById.
    --
    John Saunders
    johnwsaundersiii at hotmail
    John Saunders, Jul 15, 2004
    #1
    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. Jeff Tolman
    Replies:
    0
    Views:
    2,960
    Jeff Tolman
    Nov 4, 2003
  2. =?Utf-8?B?Tmljaw==?=

    generate control IDs dynamically

    =?Utf-8?B?Tmljaw==?=, Jun 13, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    400
    Trevor Benedict R
    Jun 13, 2004
  3. Replies:
    2
    Views:
    695
    Beat Bolli
    Jun 21, 2005
  4. Anonieko Ramos

    How do you create a drop-down hierarchical Data Grid?

    Anonieko Ramos, Nov 14, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    237
    Anonieko Ramos
    Nov 14, 2004
  5. Baiju K U

    Create a hierarchical data grid

    Baiju K U, Feb 9, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    176
    Ken Cox [Microsoft MVP]
    Feb 9, 2004
Loading...

Share This Page