Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

896 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

13 Experts available now in Live!

Get 1:1 Help Now