Solved

CheckBoxList Server Side Validation

Posted on 2013-01-14
4
360 Views
Last Modified: 2013-01-22
Hello Experts,

I have a CheckBoxList control that retrieves data from my DB (works fine). But I need to make sure a user selects at least one value from the CheckBoxList before he/she can submit the form. If he/she does not select at least one value then I want to display a message saying "Please select at least one value".

Thanks in advance!!!
0
Comment
Question by:asp_net2
  • 2
4 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 38775353
0
 
LVL 4

Author Comment

by:asp_net2
ID: 38775512
I already have a Javascript/jQuery solution. I need a Server Side solution. Thank  you for your help though.
0
 
LVL 21

Accepted Solution

by:
masterpass earned 250 total points
ID: 38776138
you can use a customvalidator and then check onservervalidate event. Below is an example

http://briancaos.wordpress.com/2012/08/16/validate-aspcheckboxlist-with-aspcustomvalidator/

hope this helps.
0
 
LVL 20

Assisted Solution

by:informaniac
informaniac earned 250 total points
ID: 38779195
Is it something like this you are looking for?
bool itemSelected = false;
            foreach (ListItem item in chk1.Items)
            {
                if (item.Selected)
                {
                    itemSelected = true;
                    break;
                }
            }
            if (!itemSelected)
            {
                // Write code for alert message here
            }

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can't disable touch pad on Windows 10 computer 16 45
SQL Query Help Top 1 and Distinct? 6 36
Finding the IIS version 5 22
SSIS Start 2 21
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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

831 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