Forum Moderators: open
I have a webform with a handful of Required Field Validators and one Custom Validator. The Custom Validation logic is bound to the ServerValidate event.
My problem is that (with all items invalid) if I hit 'Submit' (which causes validation) only the Required Field Validators are showing up. Once they have been removed (by filling in those fields) THEN (and only then) the Custom Validator shows up.
I need to know how to fix this to cause all the Validators to show up at the very first instance of validation, as this will be an annoying suprise for users who think they have completed all the tasks.
Does this have something to do with the Required Field Validators being run against client side Javascript logic? Do i need to write client side code for my custom field validator as opposed to the sever side code-behind c# i currently have in place?
Thanks in advance,
-Mike
Since you are using the 'built in' validators along with your own custom validator(s), you need to build the client side script to validate at the client level as well as the server side that you have already done to have the same behavior as the 'built in's. Your custom control is only validating at the server level right now.
You should create your own client side validation function and in the CustomValidator definition, you should add ClientValidationFunction="YourClientSideFunctionName"
For example:
<asp:customvalidator id="CV_HomePhone" runat="server" Display="Dynamic" ClientValidationFunction="CV_ClientValidatePhone"></asp:customvalidator>
function CV_ClientValidatePhone(source, args)
{
var isValid = true;
// your validation logic here
args.IsValid = isValid;
}
mark