Multiple Validators against a control

Discussion in 'ASP .Net' started by epigram, Apr 5, 2005.

  1. epigram

    epigram Guest

    I'm trying to use the ASP.NET validators to check some client-side business
    rules. I've got two ASP TextBox controls (call them tbxYear1 and tbxYear2)
    used to enter a range of years. I've got a couple things I need to check:

    1) tbxYear1 and tbxYear2 are both optional, but if values are entered they
    have to integers and non-negative
    2) if values are entered for both tbxYear1 and tbxYear2 then tbxYear1 must
    be less than tbxYear2

    It looks like I can use a couple of the validator controls to, collectively,
    make these checks. What I'd like to know is if there is a way to "short
    circuit" the comparison sequences that multiple validator controls seem to
    go through? For instance, if rule #1 is violated, then it probably doesn't
    make sense to warn the user that rule #2 has also been violated.

    I'm wondering if a CustomValidator control is the way to go here, but I'm
    note sure. I assume this type of scenario happens all the time, so I'm
    looking for a best practice.

    Thanks!
     
    epigram, Apr 5, 2005
    #1
    1. Advertising

  2. epigram

    Peter Blum Guest

    There are some cases where shortcircuiting happens:
    1. If the textbox is blank, only the RequiredFieldValidator reports an
    error.
    2. If the Type property demands Date or a number and the value is not the
    format for that type, its disabled.

    Once the field has text and matches the type, all validators will report
    errors. You are correct that one solution is to rewrite the validator using
    a CustomValidator. Another choice is to use a third party validator that can
    handle this. I am the author of "Professional Validation And More"
    (http://www.peterblum.com/vam/home.aspx). It replaces Microsoft's validators
    with 22 greatly improved validators. For example, all of the validators can
    have a rule that disables them. For example, you need a RangeValidator and
    CompareValidator and both can report an error. In my system, you can assign
    have the CompareValidator disable itself if the value is out of range (as
    the RangeValidator will be reporting an error). You can also combine the
    rules of several validators under one error message using my
    MultiConditionValidator.

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

    "epigram" <> wrote in message
    news:1112722640.c6d135992fd3376400fcd8022f29e6c4@bubbanews...
    > I'm trying to use the ASP.NET validators to check some client-side
    > business rules. I've got two ASP TextBox controls (call them tbxYear1 and
    > tbxYear2) used to enter a range of years. I've got a couple things I need
    > to check:
    >
    > 1) tbxYear1 and tbxYear2 are both optional, but if values are entered they
    > have to integers and non-negative
    > 2) if values are entered for both tbxYear1 and tbxYear2 then tbxYear1 must
    > be less than tbxYear2
    >
    > It looks like I can use a couple of the validator controls to,
    > collectively, make these checks. What I'd like to know is if there is a
    > way to "short circuit" the comparison sequences that multiple validator
    > controls seem to go through? For instance, if rule #1 is violated, then
    > it probably doesn't make sense to warn the user that rule #2 has also been
    > violated.
    >
    > I'm wondering if a CustomValidator control is the way to go here, but I'm
    > note sure. I assume this type of scenario happens all the time, so I'm
    > looking for a best practice.
    >
    > Thanks!
    >
     
    Peter Blum, Apr 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. =?Utf-8?B?QW5kZXJzQmo=?=

    Multiple validators fire at the same time

    =?Utf-8?B?QW5kZXJzQmo=?=, Aug 27, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    473
    =?Utf-8?B?QW5kZXJzQmo=?=
    Aug 27, 2004
  2. Ratman
    Replies:
    0
    Views:
    711
    Ratman
    Sep 14, 2004
  3. tshad
    Replies:
    2
    Views:
    483
    tshad
    Jan 27, 2005
  4. Just Me
    Replies:
    4
    Views:
    398
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    May 8, 2007
  5. Ryan Liu
    Replies:
    0
    Views:
    300
    Ryan Liu
    May 17, 2010
Loading...

Share This Page