views:

868

answers:

5
+3  A: 

Use CustomValidator

John Sheehan
Yep. That did the trick. I would have selected your answer, but Ian had a little more info in his, even though I already understood how you validate two bool values, I wanted others to be able to understand it. But thank you for the link, it came in handy, and was exactly what I needed.
LarryF
+3  A: 

This control (written by me) supports CheckBox and CheckBoxList:

http://www.codeproject.com/KB/validation/AtLeastOneOfValidator.aspx

Just add it to visual studio, drop it on your page, and add your checkboxes to it's Controls list. It will work like any other validator control.

Joel Coehoorn
Thanks Joel.. You know I'm gonna download this and check it out. I was able to do what I needed with a custom validator, but if I had to do even more validation on it, it may not do what I want...
LarryF
The advantage of this over a custom validator is that you get client-side validation without writing any javascript.
Joel Coehoorn
+5  A: 

Worst case you can write a CustomValidator the can do whatever you like. Sounds like what you need is along the lines of:

isValid = Check1.Checked | Check2.Checked

Ian Jacobs
Just to point out to others that might read this, you have to do a "arguments.IsValid = (CheckBoxAccident.Checked | CheckBoxTrafficViolation.Checked);", but you had the exact right idea. Thanks man!
LarryF
+1  A: 

Custom validator is the obvious solution. Also, when using a custom validator you should also check for validity on the server side just in case the javascript fails due to some reason.

P.S.: Don't always trust what the client(browser) sends you.

Hemanshu Bhojak
I can't seem to make the client side work in this case, only the server side. Because they are asp:CheckBox's I'm validating, I have to omit the ControlToValidate....
LarryF
A: 

Here is an article I wrote regarding this exact issue. I also wanted to validate multiple controls which was easy using the CustomValidator but one of the issues I was not happy about is that if you corrected the validation issue the error did not go away until you posted back.

I figured out a way to hide the error message and revalidate and wrote a small blog entry about it. Check it out and see what you think.

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

Jim Scott