Link to home
Start Free TrialLog in
Avatar of BamaErn
BamaErn

asked on

Optional Validators - Is this possible?

I have a form with three checkboxes at the top and four textboxes below them.  If the first checkbox is not checked, the first textbox is required.  If the second checkbox is not checked, the second and third textboxes are required.  If the third checkbox is checked, the fourth textbox is required.  My problem is how to validate them.  If I put a required field validator on all of the checkboxes, the validation expects all four textboxes to have data, regardless of the state of the checkboxes.  If I use the checkbox code to disable (enable = false) the individual validators as required, the validation summary no longer displays.  And I'm not even sure that this is a valid approach.

Any ideas or nudges in the right direction would be greatly appreciated.
Avatar of Joel Coehoorn
Joel Coehoorn
Flag of United States of America image

You'll have to use custom validators for the textboxes.
Avatar of BamaErn
BamaErn

ASKER

Why?  Is there an article or another thread you can point me to?
Avatar of BamaErn

ASKER

I found a solution.  I can disable the appropriate validators BUT I have to set both .enabled = false and .EnableClientScript = false.  The non-appearing summary was a red herring in that it was incorrectly placed in a div that had it's visible set to false under certain conditions.

This article confirmed to me that I could do this: http://msdn2.microsoft.com/en-us/library/bt244wbb(VS.80).aspx. (Sorry, not sure how to embed a link.)
Avatar of BamaErn

ASKER

Guess it handles the link automatically.  Nice.
ASKER CERTIFIED SOLUTION
Avatar of Alpesh Patel
Alpesh Patel
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BamaErn

ASKER

Simpler than the method I came up with.  This is better than my solution so I'm giving you the points.