Solved

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

Posted on 2007-03-29
1
322 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now