How to validate multiple CheckBox control in ASP.NET
How to validate multiple CheckBox control in ASP.NET?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sahil JaniPosted Apr 25, 2011, 6:11 AM
Most probably you wil find your answer on the following link :::
http://weblogs.asp.net/samirgeorge/archive/2009/05/02/checkboxlist-client-side-validation-using-jquery.aspx
Ankit NandekarPosted Apr 25, 2011, 6:08 AM
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
int c = 0;
protected void Page_Load(object sender, EventArgs e)
{
lblMsg.Visible = false;
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (Control chkcontrol in form1.Controls)
{
if (chkcontrol.GetType().ToString() == "System.Web.UI.WebControls.CheckBox")
{
if (((CheckBox)chkcontrol).Checked == true)
{
c++;
// write code when check box checked
}
else
{
if (c == 0)
{
lblMsg.Visible = true;
lblMsg.Text = "please select CheckBox";
}
}
}
}
}
}
Abhimanyu K VatsaPosted Apr 25, 2011, 6:05 AM
most probably we uses javascript for this but there are couple of ways, use this if you wish via javascript:
visit there for more:
http://wikiaspnet.wordpress.com/2008/08/22/validate-checkbox/