Solved

CheckBoxList Server Side Validation

Posted on 2013-01-14
4
362 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
[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
  • 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

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
Technology Resume 7 68
Problem to Office 1 43
Dictionary and array of [N] size - performance tuned 12 40
ASP.NET Complete Life Cycle for all the controls 2 17
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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

749 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