Friday, 19 August 2011

Custom Validator for CheckBoxList

Here's a custom validador for a CheckBoxList, that i used the other day:




using System.Web.UI.WebControls;

namespace SPTips.CustomValidador
{

public class CheckBoxListsValidator : BaseValidator
{


protected override bool ControlPropertiesValid()
{
Control ctrlToValidate = FindControl(ControlToValidate);
return (ctrlToValidate != null);
}


protected override bool EvaluateIsValid()
{
ListControl ctrlToValidate = FindControl(ControlToValidate) as ListControl;
if (ctrlToValidate != null)
{
return ctrlToValidate.SelectedIndex != -1;
}else
{
return false;
}
}
}
}




Cheers.

No comments:

Post a Comment