joncodo
joncodo

Reputation: 2338

Accessing Validator collection through base page

protected override void OnLoadComplete(EventArgs e)
{
    foreach (var validator in Page.Validators)
    {
        //do something
    }

    base.OnLoadComplete(e);
}

Why does var validator2 = Page.Validators[1].ControlToValidate not work? It inherits the property but I can't get access to it.

See this image - http://tinypic.com/r/14v5r0y/7

Also, is this the right place in the page cycle to get access to the validation errors?

Upvotes: 0

Views: 547

Answers (1)

James Johnson
James Johnson

Reputation: 46067

The ControlToValidate property returns a string, pertaining to the ID of the control that is being validated. Is that what you're looking for?

To get the actual validator, I believe you'd want something like this:

var validator = (BaseValidator)Page.Validators[0];
string controlToValidate = validator.ControlToValidate;

Upvotes: 2

Related Questions