I would like to have a Javascript function to be called when ever my required field validator control is true (i.e when the validator control is fired / error message shown).
Kindly let me know how this can be done.
Thanks in advance.
Assuming you're validating a TextBox control, the following snippet should do what you want:
<asp:TextBox id=txtZip runat=server OnChange="txtZipOnChange();" />
<asp:RegularExpressionValidator id="valZip" runat="server"
ControlToValidate="txtZip" ...>
<script>
function txtZipOnChange() {
// get the validator and check if it is valid
var val = <%= valZip.ClientID %>;
if (val.isvalid == false) {
// do something
}
}
</script>
Use CustomValidator control. Set the CustomValidator.ClientValidationFunction property to the javascript function and the CustomValidator.ValidateEmptyText property to false.