Validators with CSS

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

We have Validators embedded in an asp table server control. The table
server control is necessary and cannot be replaced. We want to apply CSS
formatting to the validators, but the validators have a default RED font
that appears to be difficult to remove. We could hard code in a blank font
color into the .aspx html for each validator, but that would defeat the
purpose of the CSS.

Is there a way to change the default RED color of validators in an entire
project or a different hack?

Thanks in advance.

Mark
 
If the controls are server controls (which I assume they are), you could
loop through your control collection, and when you run across a validator,
you can add an attribute to it:

myValidator.Attributes("class") = "myCssClass"

NOTE: myCssClass is the class name within your CSS file.

This might not be the best way to do it, but it does work. I know there is
also a CSS class property of web controls, I think it would be accessed like
this (but I'm unsure):

myValidator.CssClass = "myCssClass"
 
This unfortunately would be the same as simply adding a CSS attribute in the
html. The default RED would still override the CSS styling. Other
suggestions?

Thanks in advance.

Mark
 
Here's another approach. I created a replacement to Microsoft's validators
due to their numerous limitations. In mine, they all use style sheets
instead of a pre-defined font color. The product is "Professional Validation
And More" at http://www.peterblum.com/vam/home.aspx.

Professional Validation And More is designed to avoid most of the custom
coding and hacks people implement when working with Microsoft's validators.
I put together a list of the limitations in Microsoft's validators here:
http://www.peterblum.com/vam/valmain.aspx.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
Mark said:
We have Validators embedded in an asp table server control. The table
server control is necessary and cannot be replaced. We want to apply CSS
formatting to the validators, but the validators have a default RED font
that appears to be difficult to remove. We could hard code in a blank font
color into the .aspx html for each validator, but that would defeat the
purpose of the CSS.

Is there a way to change the default RED color of validators in an entire
project or a different hack?

Thanks in advance.

Mark

I have no problems removing that color: highlight the "red" in the property sheet,
press DEL and ENTER.
True, you need to do that for every validator you place of your forms/controls.

Hans Kesting
 
You could expand on Mark's idea, and do the color change progmatically.
That way, you don't have to worry about changing the color for every
validator control on your page (within your page load function.)




Pseudocode:

for each validator in my control collection
validator.ForeColor = Color.WhateverColorYouWant
next
 
Yes, but stick that validator in an table *server* control, and can you do
it then? I'm trying to find a way for our graphical interface people to
deal with this in the .aspx page consistently or with CSS without having to
do it programatically.

Thanks again.

Mark
 
Back
Top