views:

2663

answers:

2

I have a custom control that inherits from WebControl and implements IValidator, but I also want to have a property for ValidationGroup. From research, it appears I need to inherit from BaseValidator to do so. Can anybody provide a successfull example from a ASP.Net custom control that implements both BaseValidator and IValidator?

A: 

Inheriting from BaseValidator will give you all of that.

You might find the source for this control useful as a starting point: http://www.codeplex.com/UsernameAvailability

Dave Ward
What if inheriting is not an option? This is really bad move from MS. Why didn't they put the property in the interface?
Slavo
There is the IValidator interface that defines the basic methods of a validator. BaseValidator just helps you play nice with the other validation controls.
smaclell
+1  A: 

BaseValidator implements the IValidator interface. Simply have your class derive from BaseValidator and override or implement the necessary methods to support your validation logic:

public class MyValidator : BaseValidator
{
   public override bool EvaluateIsValid()
   {
     ... your code here ...
   }
}
tvanfosson