dotnetnoob
dotnetnoob

Reputation: 11350

Is there an easy method of finding Validators relating to an input control?

I've been searching Google for the past couple of hours to try an find a way of returning all Validators relating to an input control. Maybe I'm phrasing incorrectly or its not possible.

I know that there is a collection of validators accessible via Page.Validators, but what I want to do is something like this:

var myValidators = Page.Validators.Where(x => x.ControlToValidate = "abcdef");

Any ideas?

Upvotes: 4

Views: 68

Answers (1)

Adi Lester
Adi Lester

Reputation: 25211

Page.Validators holds a collection of IValidator, but most validators derive from BaseValidator, which has the ControlToValidate property, so you can do this:

var myValidators = Page.Validators.OfType<BaseValidator>
                                  .Where(x => x.ControlToValidate == "abcdef");

Upvotes: 5

Related Questions