dotnetdevcsharp
dotnetdevcsharp

Reputation: 3980

How can I make the textbox control show red as well

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>

Upvotes: 0

Views: 163

Answers (1)

Daniel
Daniel

Reputation: 13122

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.

Upvotes: 1

Related Questions