As you all know ASP.NET RequiredFieldValidator control checks that the validated control if it contains a value and for instance displays an error message if the user has not typed in text in a Textbox But the problem is RequiredFieldValidator does not work for ListControl derived controls (except ListBox) such as
* DropdownList
* CheckBoxList
* RadioButtonList
And actually it throws an exception in
* CheckControlValidationProperty(String name,String propertyName) function.
if you try to set the ControlToValidate property of the RequiredFieldValidator control to one of the above controls. So I decided to write a server side validation control to do this. Basically I have derived from BaseValidator which provides the base implementation for all validation controls. It is not an abstract class. I have overridden only two functions which are
* ControlPropertiesValid()
* EvaluateIsValid()
The first one checkes the validity of ControlToValidate property and if you return false in this function, the validation framework raises an exception. EvaluateIsValid returns the main function which checks if there is a selecteditem in the ListControl. If not returns false which means validation fails. And an interesting Point is since DropDownList control can not have a SelectedIndex property with a value of -1 , I checked against 0 so you may want to insert an empty item in the beginning.