RequiredFieldValidator - one of two fields must be filled?

G

Guest

Hi guys

Is there a way to get a Validator to work so that the user must enter text
in either one of 2 boxes? I want people to have to enter either a Contact
Name or a Company.

Any help appreciated.

Cheers


Dan
 
P

Peter Blum

ASP.NET validators don't do this automatically. The RequiredFieldValidator
only looks at a single textbox at a time.

I can offer two solutions:
1. Use the CustomValidator and write the logic yourself. On the server side,
its pretty easy. On the client-side, you have to know a bit about javascript
and DHTML.

2. I wrote a replacement to the ASP.NET validators that can easily handle
this. Professional Validation And More
(http://www.peterblum.com/vam/home.aspx) includes 22 validators that work on
many more browsers. One validator is the MultiConditionValidator. Use it to
combine other validators and build AND/OR logic expressions. In your case,
you need two required validators combined with an OR statement: TextBox1 is
required or TextBox2 is required.

Even if you don't want a commercial solution, it helps to know the
limitations of ASP.NET validators so you can better plan your project. I put
together a list that I've found at
http://www.peterblum.com/vam/valmain.aspx.

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top