views:

345

answers:

3

Is there a way to have the custom validator take the input from two controls, say for example two check boxes and make sure that only one is checked?

Or am I going about this all wrong, and more importantly if I am could you point me in the right direction?

Even if this is the wrong direction actually I would like to know how to do this in case I run into a situation where it is applicable, that is if it's possible.

Thanks for you help in advance.

+1  A: 

If you want to make sure that only one of two checkboxes are checked, you are using the wrong control.

Use a radio button to setup an exclusive selection.

Mitchel Sellers
Unfortunately it's a decision that was out of my control. The people who requested the report disliked the radio buttons and wanted check boxes. :/ Otherwise yes this would be the right solution.
Mike Keller
+1  A: 

The AJAX Control Toolkit has an exclusive checkbox list. I agree with the need for it, as radio buttons cannot be de-selected like checkboxes can.

If you're looking to roll a custom validator, it sounds like you either do it server side, at which point you can do whatever logic you want in the code behind. Conversely, you can roll your own javascript to enforce it.

JustLoren
I'll look into using the AJAX Control Toolkit, and let you know how it works. I tried using my own JavaScript but for whatever reason, the stuff that I wrote and examples I found on Google were not working. I would select one check box, then to test I would select the other, and they would both stay checked and I wasn't even able to uncheck them by clicking them again.
Mike Keller
The control toolkit didn't work for two reasons. 1) We are still runing 2.0 here with no hope of upgrading anytime soon, and the 2.0 version of the toolkit is no longer available. 2) I have to use standard html input tags rather than the checkbox controls.So it looks like I will have to write some JavaScript to get this to work.
Mike Keller
A: 

I wrote a blog article about this very thing.

http://coding.infoconex.com/post/ASPNET-CustomValidator-that-validates-multiple-controls-using-both-Server-Side-and-Client-Side-scripting.aspx

Combines both Client Side and Server Side validation and re-validates

Jim Scott