Question

I have a CustomValidator with ClientValidationFunction as below

function checkAmount(source, args) {
        var opt = document.getElementById('<%=optByAmount.ClientID %>');
        var txt = document.getElementById('<%=txtAmount.ClientID %>');
        if (opt.checked == true && txt.value == '') {
            //args.IsValid = false;
            alert('failed');
        }
        else {
            //args.IsValid = true;
            alert('passed');
        }
    }

I receive error messages 'passed' and 'failed' ONLY when the commented lines are COMMENTED. When these lines are enabled, i don't get any alert at all. Why ??

EDIT After stopping and running the code for 20 minutes (doing something other than this part of the code), It is working now !!! Thanks Damian and ub1k. I would never know why was it happening :(

No correct solution

OTHER TIPS

Could you please add additional line to your code?

alert(args);

in the first line?

I have double checked your code and it works perfectly for me. Apart from that I used CustomValidator many times and the problem is probably somewhere else. For now if you could check whether args exist it would be helpful.

Most probably because the

args.IsValid = true/false;

throws an exception and the code execution doesn't follow from then on

shouldn't args be initialized as an array somehow?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top