Problem using .NET UniqueID to reference RadioButton in Javascript?

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

  1. #1

    Default Problem using .NET UniqueID to reference RadioButton in Javascript?

    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 Guest

  2. Similar Questions and Discussions

    1. Quick Perl, HTML, CSS, JavaScript reference
      Found this site with lot's of help for different technologies. Find and click on Perl on technology list. http://www.gotapi.com Im wondering if...
    2. Problem creating radioButton in a radioButtongroup withAS
      Hi, i try to generate a form dynamically using a XML configuration file. I have a big problem with radio button and radioButton group, since i...
    3. Two Function Calls to a Database to Retrieve the UniqueID of Inserted Records
      Hi guys, I got the error message on Option 2 query as show. Actually, this code is from Inside ColdFusion MX boook. I just would like to know is...
    4. How can a control inject a style (or javascript reference) in the page HEADer?
      That is the question indeed!. It is not the first time I make some sort of web control that depends on some CSS styles. Usually one would go around...
    5. javascript disabled radiobutton doesn't get enabled in asp.net
      Hi, here's the code, i have removed the irrelevent stuff <HEAD> <title>WebForm1</title> <script language="javascript"> function...
  3. #2

    Default Re: Problem using .NET UniqueID to reference RadioButton in Javascript?

    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 [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Natty Gur 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