tie validator to a specific submit button ?

M

Mad Scientist Jr

To use a simple example, if I have a web form with two textboxes
Textbox1 and Textbox2, two Required Field Validators Validator1 (which
validates Textbox1) and Validator2 (for Textbox2), and two buttons
Button1 and Button2, can I specify that Validator1 should only
validate if Button1 is pressed, and Validator2 should only validate if
Button2 is pressed? If Button2 is pressed, we do not need Textbox1,
and if Button1 is pressed we do not need Textbox2. Note this is a
simlified example, it would not be possible to just have Textbox1 and
two buttons - in actuality there are many textboxes, each with
validators for data type and range as well as required fields, and
many buttons. I just want to know if this kind of thing is possible or
what is done in such a case. Currently validation is done in the
codebehind. Thanks.
 
C

Curt_C [MVP]

Change then to Custom Validators controlled serverside then disable/enable
them with the click events and call the Page.Validate
 
P

Peter Blum

It sounds like you need the feature called "validation groups" which is
coming in ASP.NET 2.0 (due in Spring of 2005 and available today in Beta 1
from Microsoft). This allows you to assign a group name to each button and
the validators it fires.

Without it, you have to use a different strategy that abandons client-side
validation. Someone recommended a customvalidator. I
recommend in the Click event for each button, call the Validate() method on
individual validators that are involved. Then test each validator's own
IsValid property and continue if all are true.

I offer a commercial solution for this problem that provides validation
groups and works fully on the client side: "Professional Validation And
More" (http://www.peterblum.com/vam/home.aspx).

There are many limitations in Microsoft's validator controls. I've put
together a list of them at http://www.peterblum.com/vam/valmain.aspx to help
people plan their validation designs.

--- 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,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top