0
votes

I'm using ASP.NET Pages and CustomValidator control to validate set of controls. Also I'm using ClientValidation property and my custom javascript function. My main issue is : when I setting 'ControlToValidate' property - validation function stop calling. I've check everything twice, set ID's for validator and control to validate, but still no result.

Does anybody know how to fix my situation?

P.S. Main reason why I need to set ControlToValidate property is that I want to fire validation stright after lost control focus

UPDATE : here is validator :

        <asp:CustomValidator ID="cvEmail1" runat="server" ClientValidationFunction="ValidateEmail" 
            Display="Dynamic" EnableClientScript="True" ForeColor="Red" ErrorMessage="This field is required"/>

and thi is validation function :

<script type="text/javascript">
    function ValidateEmail(sender, args) {
        var isValid = myCheck();
        args.IsValid = isValid;
    }
</script>
1
Please post your code sample. - KP.
Does the control contain text or is it empty. If the latter is the case you should set ValidateEmptyText to true. That's also true for ListControls(SelectedIndex == -1). PS: You could also force client validation onblur with Page_ClientValidate("validationGroup"). - Tim Schmelter
Control doesn't contain empty text. Actually it can, but this is not my case - Andriy Zakharko
Tim Schmelter - please, take my apologies, it seems ValidateEmptyText=true really helpful.But goodness - it wasn't work when ControlToValidate wasn't empty! - Andriy Zakharko

1 Answers

1
votes

A CustomValidator with no ControlToValidate property set validates on every postback. When you establish the ID of another control, it will only validate when that control has a value to validate; it will not validate empty text. Set ValidateEmptyText to true to enable that.

Also, you may want to post your setup, so we can assist further.