Solved

.net C# VS 2005 - check box validation (more then one checkbox)

Posted on 2007-03-29
1
339 Views
Last Modified: 2013-12-17
.net C# VS 2005 - check box validation (more then one checkbox)
Using .net standard server side validation controls.
 I need to validate that at  least one of my 5 checkboxes has been selected (checked) and tie this into an
existing validation group control.

help!
0
Comment
Question by:RSSIAdmin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 15

Accepted Solution

by:
igor_alpha earned 500 total points
ID: 18833958
Hi RSSIAdmin,
You need to add customvalidator control and code ServerValidate event handler.
For example if you have checkboxes placed in CheckBoxList you can iterate them and detect that one of them is selected:
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            args.IsValid = false;
            foreach(ListItem li in CheckBoxList1.Items)
            {
                if(li.Selected)
                {
                    args.IsValid = true;
                    break;
                }
            }
        }

If you have independent CheckBoxes you can write if/then statement to check all of them:
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
args.IsValid = false;
            if(CheckBox1.Checked)
            {
                args.IsValid = true;
            }
            else if (CheckBox2.Checked)
            {
                args.IsValid = true;
            }
           // else if .... etc...
}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question