Custom Validator not working *** FIXED ***
I have a form with the following:
- Textbox with RequiredFieldValidator
- 3 x CheckBox with a single CustomValidator
If I try submitting the form without filling in the Textbox, the RequiredFieldValidator works (form is not submitted).
But if I do not tick any of the Checkboxes, the CustomValidator does not prevent the form from being submitted (at least 1 checkbox must be ticked)
ASPX
<asp:CustomValidator ID="cvBillType" runat="server" OnServerValidate="validateBillType" ErrorMessage="*" />
<asp:CheckBox ID="chkMB" runat="server" OnCheckedChanged="chkMB_CheckedChanged" AutoPostBack="true" />
<asp:CheckBox ID="chkCredit" runat="server" OnCheckedChanged="chkCredit_CheckedChanged" AutoPostBack="true" />
<asp:CheckBox ID="chkCancellation" runat="server" OnCheckedChanged="chkCancellation_CheckedChanged" AutoPostBack="true"/>
.CS
protected void validateBillType(object source, ServerValidateEventArgs args)
{
if (chkMB.Checked || chkCredit.Checked || chkCancellation.Checked)
args.isValid = true;
else
args.isValid = false'
}
*** SOLUTION ***
I found that the Submit function wasn't checking Page.IsValid and therefore the CustomValidation was not interupting the process.