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="CheckoutAddresse s">Card Number (digits only):</asp:label></td>
<td style="WIDTH: 246px; HEIGHT: 27px"><igtxt:webmaskedit id="txtCardNumber" runat="server" Width="192px" DataMode="RawText" InputMask="#############99 9"></igtxt :webmasked it></td>
<td style="HEIGHT: 27px"><asp:customvalidator id="ccValidator" runat="server" CssClass="ErrorMessages" Display="Dynamic" ControlToValidate="txtCard Number"
ErrorMessage="Invalid Card Number" ClientValidationFunction=" ccValidati on"></asp: customvali dator><asp :requiredf ieldvalida tor id="ccRequiredValidator" runat="server" CssClass="ErrorMessages" Display="Dynamic"
ControlToValidate="txtCard Number" ErrorMessage="Card Number Required"></asp:requiredfi eldvalidat or></td>
The javascript code is:
<script language="javascript">
function ccValidation(source, arg)
{
var cardNumber = ValidatorGetValue(source.c ontroltova lidate);
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(di gitCounter ));
digitCounter--;
numberProduct = String((cardNumbersOnly.ch arAt(digit Counter) * 2));
for (var productDigitCounter = 0;
productDigitCounter < numberProduct.length;
productDigitCounter++)
{
checkSumTotal +=
parseInt(numberProduct.cha rAt(produc tDigitCoun ter));
}
}
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
<td style="WIDTH: 189px; HEIGHT: 27px"><asp:label id="Label1" runat="server" CssClass="CheckoutAddresse
<td style="WIDTH: 246px; HEIGHT: 27px"><igtxt:webmaskedit id="txtCardNumber" runat="server" Width="192px" DataMode="RawText" InputMask="#############99
<td style="HEIGHT: 27px"><asp:customvalidator
ErrorMessage="Invalid Card Number" ClientValidationFunction="
ControlToValidate="txtCard
The javascript code is:
<script language="javascript">
function ccValidation(source, arg)
{
var cardNumber = ValidatorGetValue(source.c
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(di
digitCounter--;
numberProduct = String((cardNumbersOnly.ch
for (var productDigitCounter = 0;
productDigitCounter < numberProduct.length;
productDigitCounter++)
{
checkSumTotal +=
parseInt(numberProduct.cha
}
}
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
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="ccValida tionServer SideFuncti on"
Regards.
MaulikCE
Regards.
MaulikCE
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
I'm returning true or false in the value rtnval. I've checked on it with the document.write statement above.
Thanks.
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. ServerVali dateEventA rgs) 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
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
Private Sub 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 ...
ASKER
Rejojohny,
You're right, it should be arg.IsValid. That works correctly.
Thanks.
reh2
You're right, it should be arg.IsValid. That works correctly.
Thanks.
reh2