CustomValidator doesn't give error message

Discussion in 'ASP .Net' started by COHENMARVIN, Aug 5, 2005.

  1. COHENMARVIN

    COHENMARVIN Guest

    I have a customValidator that calls a client function.
    Here is the client function
    <script language="JavaScript">
    function ClientValidate(objSource, objArgs)
    {
    var intnumber = objArgs.Value;
    if (intnumber > 5)
    {
    objArgs.IsValid = False;
    return False;
    }
    Else
    {
    objArgs.IsValid = True;
    return True;
    }
    }
    </script>

    Here is the CustomValidator:

    <ASP:CustomValidator id="valCustom" runat="server"
    ControlToValidate = "MyTextBox"
    ClientValidationFunction="ClientValidate"
    ErrorMessage="* Value must be less than or equal to 5 "
    Display="Dynamic">
    *
    </asp:CustomValidator>

    The problem is that the custom validator puts a red asterix next to the
    textbox field even when the number entered into the textbox is valid.
    It treats all numbers as wrong. Another problem involves the
    ValidationSummary control (see below)

    <ASP:ValidationSummary id="valSummary" runat="server"
    ShowSummary="True"
    ShowMessageBox = "True" DisplayMode="List" HeaderText = "<b>The
    following errors were found</b>" />

    This should give an error message when the value in "MyTextBox" is
    wrong, but it doesn't.
    -- CohenMarvin
    COHENMARVIN, Aug 5, 2005
    #1
    1. Advertising

  2. COHENMARVIN

    Peter Blum Guest

    Hi Marvin,

    I read your other thread first. I believe your best answer is to use the
    CompareValidator, Type=Integer, ValueToCompare=5, Operator=GreaterThan.

    But to offer some insight on this problem, here are my thoughts:
    1. objArgs.Value contains a string. Let's convert it to an integer first:
    var intnumber = parseInt(objArgs.Value);

    2. Don't return true or false. The result is always set in objArgs.IsValid
    (which you've done). So just remove those return statements.

    --- Peter Blum
    www.PeterBlum.com
    Email:
    Creator of "Professional Validation And More" at
    http://www.peterblum.com/vam/home.aspx

    "COHENMARVIN" <> wrote in message
    news:...
    >I have a customValidator that calls a client function.
    > Here is the client function
    > <script language="JavaScript">
    > function ClientValidate(objSource, objArgs)
    > {
    > var intnumber = objArgs.Value;
    > if (intnumber > 5)
    > {
    > objArgs.IsValid = False;
    > return False;
    > }
    > Else
    > {
    > objArgs.IsValid = True;
    > return True;
    > }
    > }
    > </script>
    >
    > Here is the CustomValidator:
    >
    > <ASP:CustomValidator id="valCustom" runat="server"
    > ControlToValidate = "MyTextBox"
    > ClientValidationFunction="ClientValidate"
    > ErrorMessage="* Value must be less than or equal to 5 "
    > Display="Dynamic">
    > *
    > </asp:CustomValidator>
    >
    > The problem is that the custom validator puts a red asterix next to the
    > textbox field even when the number entered into the textbox is valid.
    > It treats all numbers as wrong. Another problem involves the
    > ValidationSummary control (see below)
    >
    > <ASP:ValidationSummary id="valSummary" runat="server"
    > ShowSummary="True"
    > ShowMessageBox = "True" DisplayMode="List" HeaderText = "<b>The
    > following errors were found</b>" />
    >
    > This should give an error message when the value in "MyTextBox" is
    > wrong, but it doesn't.
    > -- CohenMarvin
    >
    Peter Blum, Aug 5, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Damon
    Replies:
    2
    Views:
    8,839
    blue875
    Jun 23, 2009
  2. grocery_stocker
    Replies:
    10
    Views:
    622
    Keith Thompson
    May 25, 2005
  3. Vasu
    Replies:
    2
    Views:
    594
    Knute Johnson
    Oct 18, 2008
  4. Talisker
    Replies:
    0
    Views:
    250
    Talisker
    Jun 9, 2006
  5. Replies:
    6
    Views:
    107
    Joerg Meier
    Apr 25, 2014
Loading...

Share This Page