views:

1198

answers:

3

I'm using several variants of the Validator controls (RequiredFieldValidator, CompareValidator, etc) and am using the CssClass property of the validator. I can see (via Firebug) that the class is being applied, but the validator control itself is adding a style element to it, namely color: red. But I don't want that. I want the control to use the cssclass only.

I know I can override the Forecolor attribute, but I'll have to do that on every validator in the project. And I'd really like to be able to just change my CSS Class in my stylesheet in case we have to change all the error message appearances in the future.

Anyone have any clues how to tell the Validator controls to NOT use their default styles?

+1  A: 

Have you looked at themes?

Ken Ray
Nope. Do you know that will work, or do you think it might be a good place to start?
Matt Dawdy
I think it might be one place to start. But the answer from Keltex looks simpler.
Ken Ray
Thanks Ken. Keltex's solution appears to work (at least on FF3 and IE6 in WinXP).
Matt Dawdy
+8  A: 

You can do this in your css file:

.validator
{
    color: blue !important;
}

This will override the inline red style.

Keltex
Excellent. That worked in IE6 and FF3. I can't test the others right offhand, but this will get me through for testing. I never thought to do the !important thing. For anyone who cares, the .validator class he is referring to above can be anything -- mine is called .error_text
Matt Dawdy
This is a nice example of ASP.NET sucking. Resorting to using `!important` just because ASP.NET pushes `style="color: Red"` onto you.
Deniz Dogan
FYI. As of ASP.NET 4.0: *The BaseValidator class and validation controls that derive from it no longer render red text by default.* (provided controlRenderingCompatibilityVersion is not set to "3.5")
Chris W. Rea
+3  A: 

If you use themes, you can set up your skin file to control the appearance of your validator. The problem with Forecolor inline is that the way .Net renders the default controls, it inserts a color="#..." attribute that overrides CSS at the element level. If Keltex's solution above doesn't get it for you with the !important directive, your next step is probably to use/adapt/help work on the CSS-Friendly Control Adapters project at http://www.asp.net/CSSAdapters/.

Shameless plug: Brian DeMarzo is working on extending this project at Google Code.

John Dunagan
Good advice, but wrong link (as far as I could tell). Did you mean: http://www.codeplex.com/cssfriendly ?
CMPalmer
Thanks. Edited, as I was pointing to the original version after Microsoft open-sourced(!) it, but yours is good, too.
John Dunagan
Using themes will work; I've done it multiple times to override .NET's defaults. (Red is often the right answer, but not always!)
John Rudy
Thanks for the pointers, guys. I just might delve into those other methods.
Matt Dawdy