Validators not seeming to use CSSClass

T

tshad

Are Validators able to use CSSClass?

I have the following:

<asp:RegularExpressionValidator
ControlToValidate="txtEmail" CssClass="errorMessage"
Text = "Invalid Email Address!"
ValidationExpression="\S+@\S+\.\S{2,3}"
runat="server" />
<asp:RequiredFieldValidator
ControlToValidate="txtEmail"
CssClass="errorMessage"
Text="You must enter an email"
runat="server" />

The class is defined as:

..errorMessage{
font-size:14;
color:#00FFFF;
}

I still get the text at the old size and large.

Thanks,

Tom
 
P

Peter Blum

By default, the ForeColor property is set to Red on a validator. Unless you
clear it, it will write out the style="color:red" attribute into the
validator's <span> tag. That overrides your class.

As for the font size, its possible that you need to change it so its defined
in points.
font-size:14pt;

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
H

Hans Kesting

tshad said:
Are Validators able to use CSSClass?

I have the following:

<asp:RegularExpressionValidator
ControlToValidate="txtEmail" CssClass="errorMessage"
Text = "Invalid Email Address!"
ValidationExpression="\S+@\S+\.\S{2,3}"
runat="server" />
<asp:RequiredFieldValidator
ControlToValidate="txtEmail"
CssClass="errorMessage"
Text="You must enter an email"
runat="server" />

The class is defined as:

.errorMessage{
font-size:14;
color:#00FFFF;
}

I still get the text at the old size and large.

Thanks,

Tom

You might need to specify "14pt" as the font-size,
instead of just "14".

Try adding a ForeColor=" " to the control definition,
as this seems to default to "Red", overriding your css setting.
 
T

tshad

Peter Blum said:
By default, the ForeColor property is set to Red on a validator. Unless
you clear it, it will write out the style="color:red" attribute into the
validator's <span> tag. That overrides your class.

How do I clear it so it doesn't override my class?

I thought that was the whole point of CSSClass, to override whatever
defaults were aleady in place.
As for the font size, its possible that you need to change it so its
defined in points.
font-size:14pt;

Wasn't that what I was doing?

Tom
 
T

tshad

Hans Kesting said:
You might need to specify "14pt" as the font-size,
instead of just "14".

Try adding a ForeColor=" " to the control definition,
as this seems to default to "Red", overriding your css setting.
Actually, I made a mistake. The text wasn't large, it was the same size as
always. As Peter mentioned, the Forecolor is in the span object - but the
size isn't. So it seems the Validators don't take the CSSClasses at all,
even though MS Documentation says it does.

I did add the ForeColor and Font-Size directly on the object now and it
works fine:

<asp:RegularExpressionValidator
ControlToValidate="txtEmail" Forecolor="#00FFCC"
Font-Size="14"
Text = "Invalid Email Address!"
ValidationExpression="\S+@\S+\.\S{2,3}"
runat="server" />

The problem is I wanted to use classes so that all my error messages were
consistant (which is one of the reasons to use CSS).

Thanks,

Tom
 
H

Hans Kesting

tshad said:
How do I clear it so it doesn't override my class?

Like I said before: use ForeColor=" "
I thought that was the whole point of CSSClass, to override whatever
defaults were aleady in place.

The forecolor that is specified by default in the <span> has a higher
priority than a forecolor specified in the css. Yes, css overrides
defaults, but only "real" defaults: settings that are used if you
don't specify anything. This "red" is specified in the rsulting html.
Wasn't that what I was doing?

No, as I said before, you only used "14", not "14pt".
 
T

tshad

Hans Kesting said:
Like I said before: use ForeColor=" "


The forecolor that is specified by default in the <span> has a higher
priority than a forecolor specified in the css. Yes, css overrides
defaults, but only "real" defaults: settings that are used if you
don't specify anything. This "red" is specified in the rsulting html.

But that is my point.

People have been ragging about using CSS and seem to get bent out of shape
when you don't. Older attributes are getting deprecated.

Now, it seems, you need to use both.

Is there a place to go where it specifies when you can use CSS styles and
when you can't.

MS Website has the property CSSClass. What is the point of going through
the excercise of setting up CSS styles so you can be consistent, just to
find out later that you need to go and change attributes for selected
objects (even though you are told that those object use CSS).

I am not trying to be difficult or argumentative here, just trying to find
out the best way to build my pages and code in the best and most efficient
manner.

Thanks,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top