Link to home
Start Free TrialLog in
Avatar of reh2
reh2

asked on

Why are validation results not being returned to validator control?

I have a .net customvalidator control that is is validating the following:

      <td style="WIDTH: 189px; HEIGHT: 27px"><asp:label id="Label1" runat="server" CssClass="CheckoutAddresses">Card Number (digits only):</asp:label></td>
                                    <td style="WIDTH: 246px; HEIGHT: 27px"><igtxt:webmaskedit id="txtCardNumber" runat="server" Width="192px" DataMode="RawText" InputMask="#############999"></igtxt:webmaskedit></td>
                                    <td style="HEIGHT: 27px"><asp:customvalidator id="ccValidator" runat="server" CssClass="ErrorMessages" Display="Dynamic" ControlToValidate="txtCardNumber"
                                                ErrorMessage="Invalid Card Number" ClientValidationFunction="ccValidation"></asp:customvalidator><asp:requiredfieldvalidator id="ccRequiredValidator" runat="server" CssClass="ErrorMessages" Display="Dynamic"
                                                ControlToValidate="txtCardNumber" ErrorMessage="Card Number Required"></asp:requiredfieldvalidator></td>

The javascript code is:

            <script language="javascript">
            function ccValidation(source, arg)
            {
                  var cardNumber = ValidatorGetValue(source.controltovalidate);
                  var cardNumbersOnly = cardNumber.replace(/ /g,"");
                  var numberProduct;
                  var numberProductDigitIndex;
                  var checkSumTotal = 0;
                  var cardNumberLength = cardNumbersOnly.length;
 
                  for (digitCounter = cardNumberLength - 1;
                        digitCounter >= 0;
                        digitCounter--)
                {
                        checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
                        digitCounter--;
                        numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
                        for (var productDigitCounter = 0;
                              productDigitCounter < numberProduct.length;
                              productDigitCounter++)
                        {
                              checkSumTotal +=
                              parseInt(numberProduct.charAt(productDigitCounter));
                        }
                  }
                  arg.isvalid = (checkSumTotal % 10 == 0);
                  var rtnval = (checkSumTotal % 10 == 0);
                  document.write("Cardnum = "+cardNumber+"xxx"+" val = "+arg.isvalid);
                  return rtnval ;
            }
                  
            </script>

When I leave the document.write line uncommented, it displays the cardnumber and results correctly, so I know the script is being called and is executing correctly.

The problem is that nothing ever happens on the validator control. It doesn't display an error when an incorrect cardnumber is entered.  It's as tho no results are returned to the customvalidator control. The control being validated is an Infragistics control.  I get identical results with native .net controls.  This is my first time using javascript with a customvalidator, so I'm obviously doing something wrong. Any help?

Thanks.
reh2
Avatar of Type25
Type25

Don't you need to return either true or false?
I suggest you to write Server side validation check for the same as certain browsers do not support client side validations by ASP.NET field validators...so, add the one for your custom validator by implementing similar function add following attribute OnServerValidate="ccValidationServerSideFunction"

Regards.
MaulikCE

Avatar of reh2

ASKER

Type25,
I'm returning true or false in the value rtnval.  I've checked on it with the document.write statement above.  
Thanks.
reh2

Avatar of reh2

ASKER

maulikCE,
I'm using ie6, and the document.write indicates it is executing the javascript function correctly. I was under the impression that OnServerValidate is only needed when delegation is needed.  I've got a server side validation that executes when I set a debug break to check it.  My server side validation, ccValidator_ServerValidate, is:

Private Sub ccValidator_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles ccValidator.ServerValidate  

I've added the OnServerValidate and it doesn't seem to make a difference. What I'm trying to correct is the client side error handling.

Thx.
reh2
ASKER CERTIFIED SOLUTION
Avatar of Rejojohny
Rejojohny
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

RE: Rejojohny:

If you think it as a error then "args.IsValid" is correct.

Regards.
MaulikCe
ok thx :-) .. reh2, then first try args.IsValid else the remaining options .. anyway, am sure u should have by now got the basic problem and hopefully got it working ...
Avatar of reh2

ASKER

Rejojohny,
You're right, it should be arg.IsValid.  That works correctly.
Thanks.
reh2