Jan 11

Existing RequiredFieldValidator cannot validate CheckBoxList nor RadioButtonList control. Instead it raises exception: "Control 'checkBoxList' referenced by the ControlToValidate property of 'requiredFieldValidator' cannot be validated.". Writting custom validator is quite simple process. There is one important thing to be aware of. CustomValidator performs validation if controls Text property is set. Problem is that CheckBoxList and RadioButtonList Text property is always empty, Therefore we should first set validotars ValidateEmptyText property to true.

JavaScript to perform client side validation looks like:

function MyCode_ListControlRequiredValidation(source, args) {
	var listObj = document.getElementById(source.controltovalidate);
	var listObjInputs = listObj.getElementsByTagName('input');
	for(var i = 0; i < listObjInputs.length; i++) {
		if (listObjInputs[i].checked) {
			args.IsValid = true;
	args.IsValid = false;

For server side validation we should override ControlPropertiesValid and EvaluateIsValid methods. Detailed description can be found on MSDN site.

ListControlRequiredValidator.cs (1.61 kb)

Tags: |
Comments are closed