Can't use asp:CustomValidator

Discussion in 'ASP .Net' started by K Viltersten, Mar 23, 2009.

  1. K Viltersten

    K Viltersten Guest

    I've followed the instructions for setting up a validation
    of my forms (link below). For some reason, the
    evaluation doesn't take place. My husband said he won't
    help me on this one because it's easy. It's doesn't feel
    that easy, so i'm not sure if he teases or means it... :(
    http://msdn.microsoft.com/en-us/library/f5db6z8k.aspx

    In fact, i don't seem to even enter the evaluation method
    when i try to run the site in the debugger. However,
    altering the name of it creates an error.

    <form id="form1" runat="server">
    <div>
    <asp:Label ID="InfoOnstatus" runat="server">
    No info yet! </asp:Label><br />
    <asp:TextBox ID="TextBox1" runat="server" /><br />
    <asp:CustomValidator ID="CustomValidator1" runat="server"
    ValidateEmptyText="true"
    ControlToValidate="TextBox1" OnServerValidate="TextValidate"
    ErrorMessage="Invalid!"></asp:CustomValidator>
    </div>
    </form>

    ....
    protected void TextValidate(
    object sender, ServerValidateEventArgs e) {
    InfoOnstatus.Text = "validated field";
    if (e.Value == "qw")
    e.IsValid = true;
    else
    e.IsValid = false;
    }
    ....

    What's wrong here? How can i troubleshoot it?
     
    K Viltersten, Mar 23, 2009
    #1
    1. Advertising

  2. K Viltersten

    K Viltersten Guest

    Perhaps i should add that i'm looking for dynamic
    validaton. I.e. validation as the user types. If the
    test is that the string is supposed to be between
    3 and 7 characters long i would like the status of
    the validator to switch twice when they type in
    e.g. all the digits.

    --
    Regards
    K Viltersten
     
    K Viltersten, Mar 23, 2009
    #2
    1. Advertising

  3. K Viltersten

    bruce barker Guest

    you have wo issues. first, the server validaton will only run if you
    call Page.IsValid (say in onload). second server validation only happens
    after postback. the customvalidator supports client side validtion (via
    ClientValidationFunction), but its called on lost focus (onblur). if you
    want validation on char by char you will need to write custom client
    side code. get a good javascript book.


    -- bruce (sqlwork.com)

    K Viltersten wrote:
    > Perhaps i should add that i'm looking for dynamic validaton. I.e.
    > validation as the user types. If the
    > test is that the string is supposed to be between 3 and 7 characters
    > long i would like the status of
    > the validator to switch twice when they type in
    > e.g. all the digits.
    >
    > --
    > Regards
    > K Viltersten
    >
     
    bruce barker, Mar 23, 2009
    #3
  4. K Viltersten

    miher Guest

    "K Viltersten" <> wrote in message
    news:#...
    > Perhaps i should add that i'm looking for dynamic validaton. I.e.
    > validation as the user types. If the
    > test is that the string is supposed to be between 3 and 7 characters long
    > i would like the status of
    > the validator to switch twice when they type in
    > e.g. all the digits.
    >
    > --
    > Regards
    > K Viltersten


    Hi,
    Try using a RegularExpressionValidator for this and You won't need to write
    javascript. For example You can easily write a regexp that matches only 3-7
    long strings.

    I don't know if validators support what You willing ot do, to validate at
    every keystroke, but You can use ValidatorValidate function for example from
    the onkeyup (client-side) event of the textbox to force validation.

    Hope You find this useful.
    -Zsolt
     
    miher, Mar 23, 2009
    #4
  5. K Viltersten

    K Viltersten Guest

    > Try using a RegularExpressionValidator for this and You won't need to
    > write javascript. For example You can easily write a regexp that matches
    > only 3-7 long strings.
    >
    > I don't know if validators support what You willing ot do, to validate at
    > every keystroke, but You can use ValidatorValidate function for example
    > from the onkeyup (client-side) event of the textbox to force validation.


    I'll look into it. Thanks!

    As i understand, as long as i do it on client-side, i'll
    need to play with JavaScript, right?

    --
    Regards
    K Viltersten
     
    K Viltersten, Mar 23, 2009
    #5
  6. K Viltersten

    miher Guest

    "K Viltersten" <> wrote in message
    news:ejJljk$...
    >> Try using a RegularExpressionValidator for this and You won't need to
    >> write javascript. For example You can easily write a regexp that matches
    >> only 3-7 long strings.
    >>
    >> I don't know if validators support what You willing ot do, to validate at
    >> every keystroke, but You can use ValidatorValidate function for example
    >> from the onkeyup (client-side) event of the textbox to force validation.

    >
    > I'll look into it. Thanks!
    >
    > As i understand, as long as i do it on client-side, i'll
    > need to play with JavaScript, right?
    >
    > --
    > Regards
    > K Viltersten


    Hi,
    If You use the validators as they are, You don't have to write any
    javascript, but if You have more expectations then You might have to write
    more or less.

    -Zsolt
     
    miher, Mar 24, 2009
    #6
    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. Patrice
    Replies:
    3
    Views:
    3,041
    bruce barker
    Jun 11, 2004
  2. z. f.
    Replies:
    1
    Views:
    402
    Peter Blum
    Aug 4, 2004
  3. theresa
    Replies:
    1
    Views:
    564
    =?Utf-8?B?bXVzb3NkZXY=?=
    Jun 26, 2006
  4. Replies:
    1
    Views:
    406
    Brennan Stehling
    Oct 26, 2006
  5. TS
    Replies:
    3
    Views:
    1,176
    Walter Wang [MSFT]
    Aug 9, 2007
Loading...

Share This Page