如何在自定义控件中实现BaseValidator和IValidator - ASP.Net

时间:2022-09-02 13:29:32

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?

我有一个继承自WebControl并实现IValidator的自定义控件,但我也想拥有ValidationGroup的属性。从研究来看,似乎我需要从BaseValidator继承这样做。任何人都可以从实现BaseValidator和IValidator的ASP.Net自定义控件中提供成功的示例吗?

2 个解决方案

#1


2  

Inheriting from BaseValidator will give you all of that.

从BaseValidator继承将为您提供所有这些。

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

您可能会发现此控件的源可用作起点:http://www.codeplex.com/UsernameAvailability

#2


2  

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

BaseValidator实现了IValidator接口。只需让您的类派生自BaseValidator并覆盖或实现必要的方法来支持您的验证逻辑:

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

#1


2  

Inheriting from BaseValidator will give you all of that.

从BaseValidator继承将为您提供所有这些。

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

您可能会发现此控件的源可用作起点:http://www.codeplex.com/UsernameAvailability

#2


2  

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

BaseValidator实现了IValidator接口。只需让您的类派生自BaseValidator并覆盖或实现必要的方法来支持您的验证逻辑:

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