RequiredFieldValidator - how to get rid of the default red font color

craigmoliver picture craigmoliver · Oct 20, 2008 · Viewed 25.7k times · Source

I can't seems to change the default color of the required field validator. In the source it is:

<span class="required">*</span>
<asp:RequiredFieldValidator ID="valReq_txtTracks" runat="server"
    ControlToValidate="txtTracks"
    Display="Dynamic" />

Here's what I have in my .skin file:

<asp:RequiredFieldValidator runat="server" 
    CssClass="error-text"
    ErrorMessage="required" />

In the rendered source I see:

<span class="required">*</span>
<span id="ctl00_ctl00_cphContent_cphContent_valReq_txtTracks" class="error-text" style="color:Red;display:none;">required</span>

Notice the "style=color:Red;". That needs to go. I can't override it with a css-class because it's inline CSS. What should I do?

Answer

Mark Brackett picture Mark Brackett · Oct 20, 2008

There is a RequiredFieldValidator.ForeColor property you can set to control the color. Note that if you want to set the color in CSS, then you need to set ForeColor="" to clear it on the control.