Problem using .NET UniqueID to reference RadioButton in Javascript?

Discussion in 'ASP .Net' started by David Whitney, Jul 20, 2003.

  1. Hi, all.

    I'm trying to work with some client-side scripting issues with an
    ASP.NET application. I realize I've probably done something wrong, but
    at the moment it looks to me like an inconsistency in the way
    javascript is interpreting form elements.

    I generate my Javascript from a server-side control, and use the
    UniqueID property of the control to generate what will be the final
    client-side reference. Normally, this works fine; I've tried it on
    code that enables/disables certain buttons, text boxes, etc. So,
    puffed up by my own success, I then tried to apply the same technique
    to a RadioButton. But when my JavaScript fires, I get a run-time error
    indicating it doesn't recognize the identifier its being told to
    access.

    Here's a sample of the type of generated Javascript that *works*:

    document.forms[0]["ContainerName:SubmitButton"].enabled=true;

    But if I try to use this for a *radio button*, it fails:

    if (document.forms[0]["ContainerName:RadioButtonName"].checked)
    // do something

    I'll get a client-side error that the value is null, which isn't true.

    The ASP.NET code that generates this is something like the following:

    protected override void Render(HtmlTextWriter w)
    {
    w.Write("if (document.forms[0][\"" + RadioButtonName.UniqueID +
    "\"].checked)");
    w.Write("// do something.");
    }


    In the debugger, if I replace "ContainerName:RadioButton" with
    "ContainerName_RadioButton", (from the command window with a
    debug.print statement) it *works* - just changing the colon to an
    underscore. But the other syntax works everywhere else.

    Am I missing something here, or is this just an inconsistency in the
    way Javascript handles the radiobutton references/ID's?

    Thanks,
    David
    David Whitney, Jul 20, 2003
    #1
    1. Advertising

  2. David Whitney

    Natty Gur Guest

    Hi,

    Just my two cents :

    I’m using Document.All("ControlID") And I’m using the ID property of the
    control. (I already help some people that forget to add the ID attribute
    to the control :) )

    Natty Gur, CTO
    Dao2Com Ltd.
    28th Baruch Hirsch st. Bnei-Brak
    Israel , 51114

    Phone Numbers:
    Office: +972-(0)3-5786668
    Fax: +972-(0)3-5703475
    Mobile: +972-(0)58-888377

    Know the overall picture


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur, Jul 21, 2003
    #2
    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. Henri
    Replies:
    2
    Views:
    12,089
    Henri
    May 18, 2004
  2. Kepler
    Replies:
    1
    Views:
    433
    Kepler
    Jul 7, 2004
  3. =?Utf-8?B?QXJuZQ==?=

    page.UniqueID

    =?Utf-8?B?QXJuZQ==?=, Dec 7, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    623
    =?Utf-8?B?QXJuZQ==?=
    Dec 7, 2004
  4. Ken Baltrinic

    UniqueID vs. ClientID Why are they Differenct?

    Ken Baltrinic, Mar 4, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    8,769
    Ken Baltrinic
    Mar 4, 2005
  5. =?Utf-8?B?QXJuZQ==?=

    Page.id and Page.UniqueID

    =?Utf-8?B?QXJuZQ==?=, Apr 21, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,698
    =?Utf-8?B?QXJuZQ==?=
    Apr 21, 2005
Loading...

Share This Page