Since I am new to working with C# asp.net 2010, I am asking the question on how to validate a checkbox list control.
I am adding a new checkboxlist control to a new C# asp.net 2010 web page I am in the process of working on. I am loading the values of the checkbox list controls from values I obtain in a sql server 2008 r2 database.
However, I would like to validate that at least one item in the checkbox list control has actually been selected. I would like to use a validator like the 'required validator' , 'custom validator', or some other validator to make certain the user selected something. I will run the validation when the user clicks the submit button.
Thus how would you accomplish this goal I have for using the validators? If my preferred method does not work, how would you validate that a checkbox list control has been checked? I do not want to update the database until the user has selected something.
Javeed M ShaikhPosted Oct 28, 2011, 10:11 AM
OnServerValidate="ComboBoxControlName_Validate"
and than on your server you can do the same validation, remember to set the args.IsValid = false on the server side accordingly.
scampercatPosted Oct 27, 2011, 10:23 PM
Javeed M ShaikhPosted Oct 27, 2011, 8:34 PM
You cannot attach a required validator to the checkboxlist, you need to create your own validator or you can add a custom validator and call the below client function from that:
function validateComboBoxList(source, args)
{
var comboBoxid= document.getElementById ('<%= comboboxcontrol.ClientID %>');
var checklists= comboBoxid.getElementsByTagName("input");
for(var i=0;i
if(checklists[i].checked)
{
args.IsValid = true;
return;
}
}
args.IsValid = false;
}