Solved

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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…

809 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