Validating Multiple Controls

D

David Krussow

1. Can validation controls validate more than one control at a time? E.g., a
RequiredFieldValidator control requiring that that each of 5 textboxes has
some content?

2. Can validation controls by dynamically associated with validated controls
at runtime?

My situation is this - I'm dynamically adding multiple instances of various
controls to a page - and want to validate each one. Specifically, based on
runtime conditions, the page will let the user enter from 1 to 12 address
entries - each comprised of the usual first/last name, city, street, zip
text boxes, as well as a couple of check boxes per address. While I could
certainly do the validation on the server side with custom code, I'd like to
leverage the client-side functionality enabled by the ASP.NET validatin
controls (and ideally not bloat the client-side JavaScript unnecessarily).

Any suggestions are greatly appreciated.
 
C

Chris Jackson

All validation controls inherit from the BaseValidator class, which contains
the string property ControlToValidate. It does not hold an array of strings,
but just one - you will need a validator for each control on your page. You
can dynamically add them to your form, however, in much the same way that
you can dynamically add controls.
 
P

Peter Blum

Hi David,

There are many limitations in Microsoft's validation which force you to
write custom code instead of using the existing validators. I wrote a
replacement to Microsoft's validators to overcome the limitations and
greatly expand what you can do within validation, greatly reducing the
coding.

"Professional Validation And More" (http://www.peterblum.com/vam/home.aspx)
provides 22 validators including the MultiConditionValidator which can be
used to combine the conditions of other validators into new boolean
expressions. For example, you would add the Required condition for each
textbox into this validator and set the AND operator so it does "Required1
AND Required2 AND...". It will work on the client-side and client-side
supports browsers Microsoft doesn't: Netscape/Mozilla, Opera 7 and Apple
Safari.

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

Top