?
Solved

CustomValidator Always Fails Validation using ClientValicationFunction?

Posted on 2007-10-19
17
Medium Priority
?
477 Views
Last Modified: 2008-01-09
I have a customvalidator defined that calls a javascript clientvalidatiofunction which for some reason always returns False. What am I doing wrong here?

<asp:CustomValidator ID="CustValQuantity"                                 
                             runat="server" ControlToValidate="tbDispoQuantity"
                              ClientValidationFunction="ValQuantity"
                              ErrorMessage="Dispo Quantity must be <= Available Quantity!"
                              Display="None"></asp:CustomValidator>

<script language="javascript" type="text/javascript">
function ValQuantity(source, arguments)
{

    if (arguments.value=="2")
    {
      arguments.IsValid = false;
      }
    else
    {  
    arguments.IsValid = true;
    }
</script>
0
Comment
Question by:ChiBella
  • 5
  • 4
  • 2
  • +3
17 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20111798
You can debug the Javascript code to find out.

Bob
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 20111811
arguments is a reserved word in javascript (used for something else) try this:

function ValQuantity(source, args)
{

    if (args.value=="2")
    {
      args.IsValid = false;
      }
    else
    {  
    args.IsValid = true;
    }
0
 
LVL 82

Expert Comment

by:hielo
ID: 20111817
In javascript, from withing a function , "arguments" is an array that contains all the function's arguments.
Not sure if you are passing 2 strictly as a string or not but you may not get the expected results if you pass an integer. Beware.
Try this:
function ValQuantity(source, args)
{

    if(args.value=="2")
    {
      args.IsValid = false;
      }
    else
    {  
    args.IsValid = true;
    }
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 63

Expert Comment

by:Zvonko
ID: 20111818
arguments is a built in property of JavaScript Function Object.
Take another name for the parameter.
Like this:
<script language="javascript" type="text/javascript">
function ValQuantity(source, theField){
    if (theField.value=="2"){
      theField.IsValid = false;
    } else {  
      theField.IsValid = true;
    }
</script>


0
 
LVL 63

Expert Comment

by:Zvonko
ID: 20111823
Uhps....
0
 

Author Comment

by:ChiBella
ID: 20111876
tried all your suggestions but get the same results....false.

How do I debug javascript in vs2005?
0
 
LVL 23

Expert Comment

by:basicinstinct
ID: 20111894
i'd start by doing this:

alert(args.value);
if (args.value=="2")


what does the alert say?
0
 

Author Comment

by:ChiBella
ID: 20111903
Can this have anything to do with the fact I do not have servervalidation set and I'm writing to a messagebox?
0
 

Author Comment

by:ChiBella
ID: 20111938
The alert is not returning.
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 400 total points
ID: 20111952
With 2005, and Internet Explorer:

1) Uncheck IE | Tools | Internet Options | Advanced | Browsing | Disable script debugging (Internet Explorer)

2) Under the Debug menu, there should be a Script Explorer option, and if there isn't you can put one on the menu with menu customization.

3) You will see the running .aspx rendering in a window by the Solution Explorer, where you can put breakpoints.

Bob
0
 
LVL 82

Accepted Solution

by:
hielo earned 600 total points
ID: 20111956
function ValQuantity(source, args)
{

    if(args.value=="2")
    {
      args.IsValid = false;
      }
    else
    {  
    args.IsValid = true;
    }
return args.IsValid;
}
0
 
LVL 8

Assisted Solution

by:slado2
slado2 earned 1000 total points
ID: 20111990
Javascript is case sensitive. You must use:
function ValQuantity(source, args)
{
    if(args.Value=="2")
    {
      args.IsValid = false;
      }
    else
    {  
    args.IsValid = true;
    }
0
 

Author Comment

by:ChiBella
ID: 20112044
tried that slado2....still the validation always fails:

<script language="javascript" type="text/javascript">

function ValQuantity(source, args)
{
    if(args.Value=="2")
    {
      args.IsValid = false;
      }
    else
    {  
    args.IsValid = true;
    }
</script>
0
 
LVL 82

Expert Comment

by:hielo
ID: 20112070
Try my last post. Your posted function does not have a return statement. Therefore it automatically "returns" undefined, which evaluates to false.
0
 
LVL 8

Assisted Solution

by:slado2
slado2 earned 1000 total points
ID: 20112119
Well, if you have the function defined EXACTLY as you posted then you are missing one } at the end:
<script language="javascript" type="text/javascript">

function ValQuantity(source, args)
{
    if(args.Value=="2")
    {
      args.IsValid = false;
      }
    else
    {  
    args.IsValid = true;
    }
}
</script>
0
 

Author Comment

by:ChiBella
ID: 20112178
OMG...you are right...was missing the last brace.

But TheLearnedOne...I have ScriptExplorer on the menu but it is greyed out. How do I use it?
0
 
LVL 82

Expert Comment

by:hielo
ID: 20112264
Like I said, my last post works
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

839 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