views:

13

answers:

2

Hello again,

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 :)

+1  A: 

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.

Claudio Redi
A: 

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!

nokturnal