I am trying to validate an ASP.NET radiobuttonlist using client-side javascript in a "Custom Validator" control.

Here is my javascript validator:

function ValidatePrem(source, args) {
               var Array1 = document.getElementsByName('<%= rblPremModes.ClientID %>')
               var i;
               for (i = 0; i < 4; i++) {
                 if (Array1[i].checked) {
                       if (Array1[i].value == document.getElementById('CurrPremMode').value) {
                           args.IsValid = false;

Here is the RadiobuttonList that I am trying to validate, as rendered after compilation in HTML:

<table id="ctl00_ContentPlaceHolder1_rblPremModes" border="0">
					<td><input id="ctl00_ContentPlaceHolder1_rblPremModes_0" type="radio" name="ctl00$ContentPlaceHolder1$rblPremModes" value="Monthly" /><label for="ctl00_ContentPlaceHolder1_rblPremModes_0">Monthly</label></td>
					<td><input id="ctl00_ContentPlaceHolder1_rblPremModes_1" type="radio" name="ctl00$ContentPlaceHolder1$rblPremModes" value="Quarterly" /><label for="ctl00_ContentPlaceHolder1_rblPremModes_1">Quarterly</label></td>
					<td><input id="ctl00_ContentPlaceHolder1_rblPremModes_2" type="radio" name="ctl00$ContentPlaceHolder1$rblPremModes" value="Semi-Annually" /><label for="ctl00_ContentPlaceHolder1_rblPremModes_2">Semi-Annually</label></td>
					<td><input id="ctl00_ContentPlaceHolder1_rblPremModes_3" type="radio" name="ctl00$ContentPlaceHolder1$rblPremModes" value="Annually" /><label for="ctl00_ContentPlaceHolder1_rblPremModes_3">Annually</label></td>

When I try to do the "GetElementsByName('<%= rblPremModes.ClientID %>')", the ClientID returns a name that is different from the name listed in the compiled radiobuttonlist control:
radiobuttonlistcontrol = "ctl00$ContentPlaceHolder1$rblPremModes"
rblPremModes.ClientID = "ctl00_ContentPlaceHolder1_rblPremModes"

As you can see, one name contains underlines, the other contains $ signs.

How can I make the rblPremModes.ClientID return the same name as the "Name" attribute of the compiled radiobuttonlist control?

Edited by raygberg: ASP.NET

6 Years
Discussion Span
Last Post by raygberg

By the way, I *am* a newbie here, so sorry that I didn't post this in the ASP.NET forum.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.