Solved

CheckBoxList Server Side Validation

Posted on 2013-01-14
4
329 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

15 Experts available now in Live!

Get 1:1 Help Now