[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2007-03-29
1
Medium Priority
?
353 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 2000 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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

656 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