Multiple Validators against a control

E

epigram

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!
 
P

Peter Blum

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: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top