I have 2 radio buttons (gender) and I simply want to ensure that one of these has been clicked.
Web Controls
<asp:RadioButton id="rdoGenderMale" GroupName="rdoGender" Text="male" CssClass="formtext" Runat="server"></asp:RadioButton>
<asp:RadioButton id="rdoGenderFemale" GroupName="rdoGender" Text="female" CssClass="formtext" Runat="server"></asp:RadioButton>
Custom Validator
<asp:CustomValidator runat="server" id="chkGenderValidator"
ErrorMessage="Please enter a gender value" ClientValidationFunction="chkGender" ControlToValidate="rdoGenderMale" Display="None"/>
Javascript
<script language="javascript">
function chkGender(source,args){
//default
args.IsValid = false;
with(document.frmBooking){
if((rdoGenderMale.checked) || (rdoGenderFemale.checked)){
args.IsValid = true;
}
}
return;
}
</script>
Error
System.Web.HttpException: Control 'rdoGenderMale' referenced by the ControlToValidate property of 'chkGenderValidator' cannot be validated.
I get this error when the page loads. If I change it both of these to <asp:radiobuttonlist> controls the error does not appear? Anyone any ideas?
System.Web.HttpException: Control 'rdoGenderMale' referenced by the ControlToValidate property of 'chkGender' cannot be validated.
Web Controls
<asp:RadioButton id="rdoGenderMale" GroupName="rdoGender" Text="male" CssClass="formtext" Runat="server"></asp:RadioButton>
<asp:RadioButton id="rdoGenderFemale" GroupName="rdoGender" Text="female" CssClass="formtext" Runat="server"></asp:RadioButton>
Custom Validator
<asp:CustomValidator runat="server" id="chkGenderValidator"
ErrorMessage="Please enter a gender value" ClientValidationFunction="chkGender" ControlToValidate="rdoGenderMale" Display="None"/>
Javascript
<script language="javascript">
function chkGender(source,args){
//default
args.IsValid = false;
with(document.frmBooking){
if((rdoGenderMale.checked) || (rdoGenderFemale.checked)){
args.IsValid = true;
}
}
return;
}
</script>
Error
System.Web.HttpException: Control 'rdoGenderMale' referenced by the ControlToValidate property of 'chkGenderValidator' cannot be validated.
I get this error when the page loads. If I change it both of these to <asp:radiobuttonlist> controls the error does not appear? Anyone any ideas?
System.Web.HttpException: Control 'rdoGenderMale' referenced by the ControlToValidate property of 'chkGender' cannot be validated.