0

I am using asp.net RequiredFieldValidator while it is failing and showing the correct fields what I want to do is change the active control to red i.e not display just a message so the user knows how which control and see it better

enter image description here

<asp:ValidationSummary ID="validationSummary"  runat="server" ValidationGroup="fhsMain" ForeColor="Red" HeaderText="Please ensure values are in the following fields" />

 <div class="form-group">
                        <label class="col-md-4 control-label" for="textinput">
                            First Name</label>
                        <div class="col-md-8">
                            <telerik:RadTextBox ID="txtFirstName" CssClass="form-control" Width="60%" Skin="Bootstrap" runat="server"></telerik:RadTextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="fhsMain" runat="server" ControlToValidate="txtFirstName" ErrorMessage="First Name"></asp:RequiredFieldValidator>
                        </div>
</div>
Mauricio Gracia Gutierrez
  • 10,288
  • 6
  • 68
  • 99
c-sharp-and-swiftui-devni
  • 3,743
  • 4
  • 39
  • 100
  • 1
    Possible duplicate of [How do I highlight a textbox border red when it is required?](http://stackoverflow.com/questions/21237890/how-do-i-highlight-a-textbox-border-red-when-it-is-required) – Clint B Jun 09 '16 at 13:37
  • There is no built in way to do this with the RequiredFieldValidator - easiest way would probably be use a CustomValidator and do it on the server. – Laslos Jun 09 '16 at 13:38
  • 1
    Possible duplicate of [Change Text Box Color using Required Field Validator. No Extender Controls Please](http://stackoverflow.com/questions/196859/change-text-box-color-using-required-field-validator-no-extender-controls-pleas) – Pranav Patel Jun 09 '16 at 13:38
  • You can check this post, where Znar did something similar for the border: [RequiredFieldValidator,… effect on others controls](http://stackoverflow.com/questions/36167884/requiredfieldvalidator-effect-on-others-controls/36181328#36181328). – ConnorsFan Jun 09 '16 at 16:29

1 Answers1

1

Based upon what you indicate as your goal I believe you should add the Text attribute to your validator (see the last line in the example below). This is separate from the ErrorMessage which renders in your ValidationSummary. When the validator fails, the text will display where you put the validator and the errormessage will display in your summary.

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ValidationGroup="fhsMain" 
runat="server" ControlToValidate="txtFirstName" ErrorMessage="First Name" 
Text="Text To Display"></asp:RequiredFieldValidator>

If you really want the input itself to change colors then you're going to need to implement some custom Javascript or utilize an external library like formvalidation.io.

Daniel
  • 12,982
  • 3
  • 36
  • 60
  • Just a note: The answers on the linked questions provide excellent examples of possible Javascript you could use. This answer focuses on explaining how to not display "just a message". – Daniel Jun 09 '16 at 13:45
  • Daniel that is not what i mean i was wanting to highlight the overall textbox at present. – c-sharp-and-swiftui-devni Jun 09 '16 at 14:18