Javascript – ValidationSummary with Client Side & Server Side Validation

ccustomvalidatorjavascriptnetvalidationsummary

If you use a CustomValidator control and a ValidationSummary control within an aspx page for server side validation you can set the ErrorMessage of the validator and its Text value will appear in place and the ErrorMessage value will be displayed within the ValidationSummary control.

Nice.

Now, what if I also perform validation on the client side in javascript, is it possible to perform the same kind of validation message display as if the server side code had fired? So that the ValidationSummary would display its usual HeaderText along with your additional ErrorMessage and the CustomValidator would display its Text value (e.g. *)

I can probably fake it for client side vs. server side but it would be nice to use the existing controls if at all possible.

Thanks in advance for any ideas or suggestions

Best Answer

You can make the validator itself run on the client side when you set EnableClientScript to be true. ClientValidationFunction can then be set to the name of the javascript function that you write to validate the control. The rest of the CustomValidator control's behavior will tie in with the ValidationSummary just like any other validator, including putting the ErrorMessage up in the header, etc. etc.