By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,300 Members | 1,867 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,300 IT Pros & Developers. It's quick & easy.

Multiple Validators against a control

P: n/a
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!
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"epigram" <no****@spammy.com> wrote in message
news:1112722640.c6d135992fd3376400fcd8022f29e6c4@b ubbanews...
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!

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.