Home
Manage Your Code
Snippet: CheckBoxList Custom Validator (C#)
Title: CheckBoxList Custom Validator Language: C#
Description: CheckBoxListValidator Views: 408
Author: Richard Bogle Date Added: 7/11/2008
Copy Code  
1using System;
2using System.Web;
3using System.Web.UI;
4using System.Web.UI.WebControls;
5
6namespace Esc.Common
7{
8    public class CheckBoxListValidator : BaseValidator
9    {
10        #region Fields   ...        #endregion
15        #region Properties   ...        #endregion
28        #region Protected Methods   ...        #endregion
93    }
94}
Usage
private readonly CheckBoxListValidator myValidator = new CheckBoxListValidator();
myValidator.ID = "myValidator";
myValidator.ControlToValidate = myCheckBoxList.ClientID;
myValidator.ErrorMessage = "Error.";
myValidator.ValidationGroup = validationGroup;
Controls.Add(myValidator);
Notes
Needs Custom Validators Client-side (Validators.js) also. CheckBoxListValidatorCanOnlyValidateCheckBoxList = "The CheckBoxListValidator can only validate controls of type CheckBoxList." ControlToValidatePropertyCannotBeBlank = "The ControlToValidate property of '{0}' cannot be blank."