getelementbyid cant find runtime id

Discussion in 'ASP .Net' started by Beemer Biker, Nov 12, 2006.

  1. Beemer Biker

    Beemer Biker Guest

    I am adding at bindtime an htmlbutton and an html dropdownlist. The idea is
    to select the item in the list, hit the button and my callback code uses the
    ID.selectedindex to act on the item that was selected. I tested it all out
    by dropping a button and a DDL on a form. Worked ok. Then I wrote the code
    that automatically added the the button and the DDL to a templated column.
    The button callback works just fine, but document.getelementbyid returns
    null. I know how to make this work if I replace the client side objects
    with server side. I just thought I could do it on the client side and avoid
    postbacks. I guess I could store the value of the DDL during an onchange
    somewhere and then the button would get that value (or 0 if nothing was
    changed???)

    Is there a better way to handle this? Seems there should be some way the
    button callback could get the value of the index that was selected. Maybe I
    am doing something wrong?

    ...TIA..


    --
    ==========================================
    Joseph "Beemer Biker" Stateson Ask about my 99'R1100RT
    http://ResearchRiders.org
    ==========================================
    Beemer Biker, Nov 12, 2006
    #1
    1. Advertising

  2. If you view the html source of your page, you will see that the ddl's id is
    not what you think It is made out of parts. You may want to correct the id
    you are passing to getElementById to include all the parts.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]


    "Beemer Biker" <> wrote in message
    news:...
    >I am adding at bindtime an htmlbutton and an html dropdownlist. The idea
    >is to select the item in the list, hit the button and my callback code uses
    >the ID.selectedindex to act on the item that was selected. I tested it all
    >out by dropping a button and a DDL on a form. Worked ok. Then I wrote the
    >code that automatically added the the button and the DDL to a templated
    >column. The button callback works just fine, but document.getelementbyid
    >returns null. I know how to make this work if I replace the client side
    >objects with server side. I just thought I could do it on the client side
    >and avoid postbacks. I guess I could store the value of the DDL during an
    >onchange somewhere and then the button would get that value (or 0 if
    >nothing was changed???)
    >
    > Is there a better way to handle this? Seems there should be some way the
    > button callback could get the value of the index that was selected. Maybe
    > I am doing something wrong?
    >
    > ..TIA..
    >
    >
    > --
    > ==========================================
    > Joseph "Beemer Biker" Stateson Ask about my 99'R1100RT
    > http://ResearchRiders.org
    > ==========================================
    >
    Eliyahu Goldin, Nov 12, 2006
    #2
    1. Advertising

  3. Beemer Biker

    Beemer Biker Guest

    "Eliyahu Goldin" <> wrote in
    message news:uZ$...
    > If you view the html source of your page, you will see that the ddl's id
    > is not what you think It is made out of parts. You may want to correct the
    > id you are passing to getElementById to include all the parts.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    >
    >


    Thanks Eliyahu, shortly after posting this topic, like about 30 seconds
    later, I read the same response to a similar post by another individual
    working with radio buttons (instead of drop down list)
    news:
    I didnt realize the the actual id's were different than the ones I assigned.
    I had coded something like "onclick="ProcessSelected('ddl_id')" but I see
    now that ddl_id would never have have worked because at a minimum there are
    more than one of them in the grid plus the names are assigned as you say.

    What if I passed "this" instead of the ddl_id. I am at home and not at work
    where I got VS8 so I cant run a quick test. Would this.id maybe get the
    correct id?
    There is another discussion here FWIW

    ...thanks..
    Beemer Biker, Nov 12, 2006
    #3
  4. Beemer Biker

    Beemer Biker Guest

    going to answer my own question:

    > I had coded something like "onclick="ProcessSelected('ddl_id')" but I see
    > now that ddl_id would never have have worked because at a minimum there
    > are more than one of them in the grid plus the names are assigned as you
    > say.
    >
    > What if I passed "this" instead of the ddl_id. I am at home and not at
    > work where I got VS8 so I cant run a quick test. Would this.id maybe get
    > the correct id?


    "this" would be the button object, not the ddl object so this.id would not
    get me the value of the selected index


    > There is another discussion here FWIW
    >
    > ..thanks..
    >
    >
    Beemer Biker, Nov 12, 2006
    #4
  5. Beemer Biker

    Mark Rae Guest

    "Beemer Biker" <> wrote in message
    news:...

    >> I had coded something like "onclick="ProcessSelected('ddl_id')"


    Do it this way, and you'll never be bothered by this problem again:

    <asp:Button ID="MyButton" runat="server" Text="Test"
    OnClientClick="alert('<%=MyButton.ClientID%>'); />
    Mark Rae, Nov 12, 2006
    #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. Franck
    Replies:
    3
    Views:
    2,387
    Eliyahu Goldin
    Aug 25, 2005
  2. Nagaraj
    Replies:
    1
    Views:
    853
    Lionel B
    Mar 1, 2007
  3. Frank
    Replies:
    2
    Views:
    3,969
    Frank
    Jan 10, 2009
  4. Jake Barnes
    Replies:
    2
    Views:
    116
  5. Katie
    Replies:
    2
    Views:
    189
    Randy Webb
    Jul 20, 2006
Loading...

Share This Page