I have the following code. When I press my save button, the three requiredfieldvalidators run fine and work properly. However my custom validator does not work. It does not fire the event at all. I have standard text boxes and a validationsummary control. Is there any reason why it might not be working?
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtForename" Display="None" ErrorMessage="Must enter a valid first name." />
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtSurname" Display="None" ErrorMessage="Must enter a valid last name." />
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtEmail" Display="None" ErrorMessage="Must enter a valid e-mail address." />
<asp:CustomValidator runat="server" OnServerValidate="CheckAtLeastOnePhoneNumber"
ErrorMessage="Must enter at least one phone number." Display="None"
ValidateEmptyText="True" />
<script runat="server">
void CheckAtLeastOnePhoneNumber(Object s, ServerValidateEventArgs e)
{
if (txtMobileNumber.Text.Equals("") &&
txtWorkNumber.Text.Equals("") &&
txtHomeNumber.Text.Equals(""))
{
e.IsValid = false;
}
}
</script>