?
Solved

Why are validation results not being returned to validator control?

Posted on 2005-04-11
8
Medium Priority
?
723 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:reh2
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 9

Expert Comment

by:Type25
ID: 13759930
Don't you need to return either true or false?
0
 
LVL 6

Expert Comment

by:Maulik Modi
ID: 13761856
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

0
 

Author Comment

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

0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:reh2
ID: 13762630
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
0
 
LVL 26

Accepted Solution

by:
Rejojohny earned 2000 total points
ID: 13762640
javascript is case sensitive .. arg.isValid might not be the way u have defined .. I do not remeber how it is.. but i remember it is not the way mentioned in MSDN too (which is "IsValid").. had a lot of problem finding the solution when i had faced a similar problem ..  so i would advice that u try all sorts of combination .. isValid, IsValid, Isvalid etc ...
0
 
LVL 6

Expert Comment

by:Maulik Modi
ID: 13762741

RE: Rejojohny:

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

Regards.
MaulikCe
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 13762802
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 ...
0
 

Author Comment

by:reh2
ID: 13762856
Rejojohny,
You're right, it should be arg.IsValid.  That works correctly.
Thanks.
reh2
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
There is a wide range of advantages associated with the use of ASP.NET. This is why this programming framework is used to create excellent enterprise-class websites, technologies, and web applications.
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question