nokturnal
nokturnal

Reputation: 2869

ASP.net: Searching for all validation controls on a page

I want to search an ASP.net form for all types of validation controls and programmatically add some attributes to them such as ForeColor. Can someone point me in the right direction on this?

Cheers and thanks Stackers :)

Upvotes: 1

Views: 2536

Answers (2)

nokturnal
nokturnal

Reputation: 2869

That turned out to be easier than I first thought thanks to Claudio's tips:

    foreach (IValidator cValidator in Page.GetValidators(null))
    {
        BaseValidator bv = (cValidator as BaseValidator);
        bv.CssClass = "Error";
        bv.Display = ValidatorDisplay.Dynamic;
        bv.ForeColor = System.Drawing.Color.Empty;
    }

Thanks!

Upvotes: 1

Claudio Redi
Claudio Redi

Reputation: 68400

I think you may get to something using the method Page.GetValidators()

It returns a collection of IValidator so you would need to cast it to the appropriate class

Here you have a sample usage.

Upvotes: 2

Related Questions