how can i make Valdator's color red?
Asked Answered
S

3

6

i have a problem that i have specified the color of RequiredFieldValidator to red but when i publish the website on net the color of RequiredFieldValidator is changed to black. it works fine in localhost. what could be the problem ? thanks in advance..

this is the image like what i want

Sleety answered 16/1, 2012 at 6:5 Comment(2)
i have just specified the Validators's property ForeColor = red. but it doesn't workSleety
can you try using css styles, give a class .errorMsg{color:red;}Unearth
G
3

By default the validator is red - you shouldn't need to change it. Check your css to make sure it is not getting over ridden by anything. Also check the class that the requiredfieldvalidator is set to and make sure it does not include a color property.

Gharry answered 16/1, 2012 at 7:7 Comment(1)
Just to be extra clear: As Jason mentions, the default color is ONLY red prior to .net 4.0. If you do not want to change the color of EVERY single validator in the entire website you will need to update your web.config the way Syed mentions. It is probably a good idea to update the web config for any existing sites that were designed < 4.0 and then moved to 4.0+ unless you have tested each and every page.Laurentium
F
14

Rohan,

This may have been your issue. I had the same problem.

By default, framework 4.0 will make all validator error messages black. You will need to explicitly set the ForeColor of all validators to red if you target framework 4.0.

Your source output in 3.5:

<span id="ctl01_YourControl" style="color:Red;visibility:hidden;">*</span>

Your source output in 4.0:

<span id="ctl01_YourControl" style="visibility:hidden;">*</span>
Fijian answered 10/11, 2012 at 1:26 Comment(1)
This is exactly what happened to me. I was testing in .NET 2.0 but production was running in 4.0. Thanks for the tip!Phrenic
D
7

ASP.NET 4.0 has changes to output cleaner code, which include:

xhtmlConformance is set to Strict. Menus are rendered as lists rather than tables Extraneous properties like border=0 are removed from the emitted markup. Even the error text on validation controls is no longer set to red. The rendering of the outer table for templated controls can now be controlled with the newRenderOuterTable property. For compatibility, you can make your output look the same as it did in ASP.NET 3.5 with the controlRenderingCompatibilityVersion

> <?xml version="1.0"?> <configuration>   <system.web>
>     <compilation debug="false" targetFramework="4.0" />
>     <pages controlRenderingCompatibilityVersion="3.5" />   </system.web> </configuration>

More information is available at http://msdn.microsoft.com/en-us/library/system.web.ui.control.renderingcompatibility.aspx.

I'm so happy to have resolved this. And I'm surprised I couldn't find more people posting about this same issue. It looks like the options in my case are to use this compatibility setting or set the ForeColor of all my validation controls to Red. (I'll probably do that latter.)

Dharana answered 23/6, 2014 at 13:27 Comment(1)
setting the controlRenderingCompatiblityVersion to 3.5 solved my problemMorphinism
G
3

By default the validator is red - you shouldn't need to change it. Check your css to make sure it is not getting over ridden by anything. Also check the class that the requiredfieldvalidator is set to and make sure it does not include a color property.

Gharry answered 16/1, 2012 at 7:7 Comment(1)
Just to be extra clear: As Jason mentions, the default color is ONLY red prior to .net 4.0. If you do not want to change the color of EVERY single validator in the entire website you will need to update your web.config the way Syed mentions. It is probably a good idea to update the web config for any existing sites that were designed < 4.0 and then moved to 4.0+ unless you have tested each and every page.Laurentium

© 2022 - 2024 — McMap. All rights reserved.