CustomValidator Always Fails Validation using ClientValicationFunction?

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>
ChiBellaAsked:
Who is Participating?
 
hieloConnect With a Mentor Commented:
function ValQuantity(source, args)
{

    if(args.value=="2")
    {
      args.IsValid = false;
      }
    else
    {  
    args.IsValid = true;
    }
return args.IsValid;
}
0
 
Bob LearnedCommented:
You can debug the Javascript code to find out.

Bob
0
 
basicinstinctCommented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
hieloCommented:
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
 
ZvonkoSystems architectCommented:
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
 
ZvonkoSystems architectCommented:
Uhps....
0
 
ChiBellaAuthor Commented:
tried all your suggestions but get the same results....false.

How do I debug javascript in vs2005?
0
 
basicinstinctCommented:
i'd start by doing this:

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


what does the alert say?
0
 
ChiBellaAuthor Commented:
Can this have anything to do with the fact I do not have servervalidation set and I'm writing to a messagebox?
0
 
ChiBellaAuthor Commented:
The alert is not returning.
0
 
Bob LearnedConnect With a Mentor Commented:
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
 
slado2Connect With a Mentor Commented:
Javascript is case sensitive. You must use:
function ValQuantity(source, args)
{
    if(args.Value=="2")
    {
      args.IsValid = false;
      }
    else
    {  
    args.IsValid = true;
    }
0
 
ChiBellaAuthor Commented:
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
 
hieloCommented:
Try my last post. Your posted function does not have a return statement. Therefore it automatically "returns" undefined, which evaluates to false.
0
 
slado2Connect With a Mentor Commented:
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
 
ChiBellaAuthor Commented:
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
 
hieloCommented:
Like I said, my last post works
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.