You can't use a requiredfieldvalidator. You could write a custom validator
Main Topics
Browse All TopicsI have 10 checkboxes in a web form.
Practically, If NO ONE of them is selected, when a button are pressed, I would like to fire a Requiredfieldvalidator for a textfield.
How would I do this?
I tried some loop through checkboxes but didn't get it work, neither how I would fire the validator only if no checkbox is enabled.
Thank's in advanced.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
If you are working with masterpages, then you can do this
Add a label to you page and rename the checkboxs from CheckBox1 to CheckBox10
For x As Byte = 1 to 10
Dim ctrl As Control = FindControl("ctl00$Content
If (Not ctrl Is Nothing) Then
If CType(ctrl, CheckBox).Checked Then
' At least one checked
Exit For
End If
End If
Next X
mrichmon,
Thank's then I need help using it with a CustomValidator :). Never placed one.
jpaulino,
Thank's I will try it. It looks familiar to the other loop I used. Then the main question is how I connect this to fire the validator IF no boxes are enabled?
Would there be possible to set a RequiredFieldValidator on the textbox. Then set CausesValidation of the textbox to False, if the loop through textboxes says "noone checked", when clicking the button? Or is this check of causesvalidation occuring to late?
Is this correct ?
Does your structure as MasterPage and ChildPage ? This is for that check if this is correct.
"ctl00$ContentPlaceHolder1
If is just a simple page you can try this:
For x As Byte = 1 to 10
Dim ctrl As Control = FindControl("CheckBox" & x.ToString)
If (Not ctrl Is Nothing) Then
If CType(ctrl, CheckBox).Checked Then
' At least one checked
Exit For
End If
End If
Next X
Here is an example you could follow:
1) Create a new ASP.NET Web Form
2) On the form add the following:
10 Check Boxes
1 Text box
1 Custom Validator
1 Button
3) Select the Custom Validator and edit it’s properties
Set the ControlToValidate property to the name of the text box on the form
Set the ValidateEmptyText property to True
4) Double click the custom validator to get a method attached to the default event, Server Validate
6) Use this code in the event.
(attached)
The ideas presented here are really just a combination of the other posts on this topic already.
It's set to true, as you told in your steps. And yes, i'm stepping from breakpoints.
I've checked with an another EE-question where someone telled this
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="txtS3_1
ValidateEmptyText="True"><
should be
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="txtS3_1
ValidateEmptyText="True" OnServerValidate="CustomVa
And now the code steps correctly into this event! Then it isn't fire the validator, instead it's fulfill the button_click event (continue to next page).
If I check any checkbox AND wrote something in the textbox, the customvalidator_servervali
If I don't press any checkbox, BUT wrote something in the textbox, it's also bypass the servervalidate event.
IF I don't check any checkbox and don't write anything in the textbox -- The servervalidate event is fired.
IF I check a checkbox and don't write in the textbox, the servervalidate event are fired.
Is this helping you, helping me forward?
As I understand it you want the page to be invalid if and only if, no checkboxes are checked and the textbox is empty. Keeping that in mind.
If I check any checkbox AND wrote something in the textbox, the customvalidator_servervali
-This is valid because at least one checkbox is checked.
If I don't press any checkbox, BUT wrote something in the textbox, it's also bypass the servervalidate event.
-This is valid because although there are no check boxes, there is something in the text box.
IF I don't check any checkbox and don't write anything in the textbox -- The servervalidate event is fired.
-This is an invalid situation because all checkboxes are empty and the textbox is empty.
IF I check a checkbox and don't write in the textbox, the servervalidate event are fired.
This is valid because at least one checkbox is checked.
What do you desire to happen in each of these situations? I was only basing my response on your initial question.
Xersoft, your repeating me correctly! I was mix up the validations and the they works (this args thing). Now I also tried this on more pages and seems to understand and can control it. Thank's a lot for the help! My next step in thisd world is to control a datatable that fills with data based on what users do on a webform, then save it to a database.
If you want to try that question, it's here:
http://www.experts-exchang
Business Accounts
Answer for Membership
by: dingirPosted on 2008-01-10 at 13:15:40ID: 20631308
I'm sorry, this is a ASP.NET VB Question! Not C#.