Custom Validator newbie question

Discussion in 'ASP .Net' started by MattB, Nov 23, 2004.

  1. MattB

    MattB Guest

    Hi. I've looked at a couple of examples and I thought I had a handle on
    this, but it's not working like I expected.

    I created a custom validator on my form that (for now) only has a server
    side check that performs a luhn check on a credit card number. I've created
    the validator, and the server side code to check the card number. The
    problem is, I can enter invalid numbers and the validator never seems to do
    anything - the numbers are accepted like there's no problem.

    In stepping through this in the debugger, I see my validation sub execute,
    and args.IsValid evaluates to false, but then I see no indication of this on
    the page, like the validator never hears back from the sub I created.

    Any ideas what I've done wrong? Thanks!

    Matt
    MattB, Nov 23, 2004
    #1
    1. Advertising

  2. MattB

    Teemu Keiski Guest

    Hi,

    in the logic that is dependable on the validator, do you check Page.IsValid
    or validator.IsValid before letting that code run? You need to check that
    manually at server-side to ensure that validion is enforced.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsider
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke


    "MattB" <> wrote in message
    news:...
    > Hi. I've looked at a couple of examples and I thought I had a handle on
    > this, but it's not working like I expected.
    >
    > I created a custom validator on my form that (for now) only has a server
    > side check that performs a luhn check on a credit card number. I've

    created
    > the validator, and the server side code to check the card number. The
    > problem is, I can enter invalid numbers and the validator never seems to

    do
    > anything - the numbers are accepted like there's no problem.
    >
    > In stepping through this in the debugger, I see my validation sub execute,
    > and args.IsValid evaluates to false, but then I see no indication of this

    on
    > the page, like the validator never hears back from the sub I created.
    >
    > Any ideas what I've done wrong? Thanks!
    >
    > Matt
    >
    >
    Teemu Keiski, Nov 23, 2004
    #2
    1. Advertising

  3. MattB

    MattB Guest

    I don't check those, but the other validators on the page work fine. They
    are not custom (regex, compare, required field).
    So even if those work ok, would this make my custom validator not work?
    Thanks!

    Teemu Keiski wrote:
    > Hi,
    >
    > in the logic that is dependable on the validator, do you check
    > Page.IsValid or validator.IsValid before letting that code run? You
    > need to check that manually at server-side to ensure that validion is
    > enforced.
    >
    >
    > "MattB" <> wrote in message
    > news:...
    >> Hi. I've looked at a couple of examples and I thought I had a handle
    >> on this, but it's not working like I expected.
    >>
    >> I created a custom validator on my form that (for now) only has a
    >> server side check that performs a luhn check on a credit card
    >> number. I've created the validator, and the server side code to
    >> check the card number. The problem is, I can enter invalid numbers
    >> and the validator never seems to do anything - the numbers are
    >> accepted like there's no problem.
    >>
    >> In stepping through this in the debugger, I see my validation sub
    >> execute, and args.IsValid evaluates to false, but then I see no
    >> indication of this on the page, like the validator never hears back
    >> from the sub I created.
    >>
    >> Any ideas what I've done wrong? Thanks!
    >>
    >> Matt
    MattB, Nov 23, 2004
    #3
  4. MattB

    Teemu Keiski Guest

    If those other validators use client-side validation (in IE they do by
    default) they prevent the postback on error scenarios, so that already
    prevents the server-side code from running (even if your custom validator
    would be OK) as validation goes all-or-nothing with the page.

    To be safe for other browsers than IE, you need to check Page.IsValid or
    validator.IsValid (depending on your situation if you want to overcome the
    whole-page validation limitation) always when you have validators on the
    page. Also to turn the aspect, writing only server-side check wires the
    validation only when postback happens, so with such validator client-side
    checks won't happen so Page:IsValid is your only way (buolt-in validation
    controls work only at server.side for non-IE browsers)

    Just to say that there's also a good commercial validation product on the
    market, Peter Blum's Professional Validation And More, if you might be in
    need for such. http://www.peterblum.com/VAM/Home.aspx It overcomes many
    limitations that built-in ASp.NET validation controls have.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsider
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke


    "MattB" <> wrote in message
    news:...
    > I don't check those, but the other validators on the page work fine. They
    > are not custom (regex, compare, required field).
    > So even if those work ok, would this make my custom validator not work?
    > Thanks!
    >
    > Teemu Keiski wrote:
    > > Hi,
    > >
    > > in the logic that is dependable on the validator, do you check
    > > Page.IsValid or validator.IsValid before letting that code run? You
    > > need to check that manually at server-side to ensure that validion is
    > > enforced.
    > >
    > >
    > > "MattB" <> wrote in message
    > > news:...
    > >> Hi. I've looked at a couple of examples and I thought I had a handle
    > >> on this, but it's not working like I expected.
    > >>
    > >> I created a custom validator on my form that (for now) only has a
    > >> server side check that performs a luhn check on a credit card
    > >> number. I've created the validator, and the server side code to
    > >> check the card number. The problem is, I can enter invalid numbers
    > >> and the validator never seems to do anything - the numbers are
    > >> accepted like there's no problem.
    > >>
    > >> In stepping through this in the debugger, I see my validation sub
    > >> execute, and args.IsValid evaluates to false, but then I see no
    > >> indication of this on the page, like the validator never hears back
    > >> from the sub I created.
    > >>
    > >> Any ideas what I've done wrong? Thanks!
    > >>
    > >> Matt

    >
    >
    Teemu Keiski, Nov 23, 2004
    #4
    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. Angela

    Custom Validator Control - newbie

    Angela, Jul 21, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    2,499
    Shan Plourde
    Jul 26, 2004
  2. Ken Varn
    Replies:
    1
    Views:
    2,628
    Peter Blum
    Nov 2, 2004
  3. =?Utf-8?B?Qi4gQ2hlcm5pY2s=?=

    Newbie mistake or Custom Validator bug?

    =?Utf-8?B?Qi4gQ2hlcm5pY2s=?=, Feb 22, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    2,135
    =?Utf-8?B?Qi4gQ2hlcm5pY2s=?=
    Feb 23, 2006
  4. Replies:
    4
    Views:
    884
    Richter~9.6
    Feb 13, 2007
  5. Scott Yenor

    How to get custom control to work with custom validator

    Scott Yenor, Jan 27, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    196
    Scott Yenor
    Jan 27, 2004
Loading...

Share This Page