0
 <asp:TextBox ID="txt_Subject" runat="server" CssClass="txt_box"></asp:TextBox>
 <asp:RequiredFieldValidator ID="valSubjectRequired" ControlToValidate="txt_Subject"
                ErrorMessage="Subject is a required field." EnableClientScript="true" Display="None"
                runat="server" />
 <asp:ValidationSummary ID="ValSummary" HeaderText="" ShowSummary="True" DisplayMode="List"
                runat="server" Style="z-index: 1; left: 437px; top: 118px; color: Maroon; />

I have this text box and validation controls. I have many text box and every text box is a required field I display the error message in the validation summary. I have positioned the validation summary below the form. I have text box and labels inside the table tag. How can I display the error message next to the text box. I have to scroll down and Up to find out what are the req fields. Instead I want to display next to the text box.

2 Answers 2

1

If you don't want to show the validation summary then you can delete it or set the "ShowSummary" to false. Personally I do this and then set the "ShowMessageBox" to true so the user gets an alert.

The text that displays in the alert is whatever you put in the "ErrorMessage" of the "RequiredFieldValidator". The "RequiredFieldValidator" also has a property called "Text". This becomes your error message next to the text box.

<asp:TextBox ID="txt_Subject" runat="server" CssClass="txt_box" />

<asp:RequiredFieldValidator ID="valSubjectRequired" runat="server" ControlToValidate="txt_Subject" ErrorMessage="Error message shown in pop-up"  Text="Error Message shown next to the text box" />

<asp:ValidationSummary ID="ValSummary" runat="server" HeaderText="" ShowSummary="false" ShowMessageBox="true" />
Sign up to request clarification or add additional context in comments.

Comments

0

If I understood correctly, you want to display the validation error messages next to the textboxes and don't need to display them at the bottom. If this is so, remove the ValidationSummary control from the page. This results in displaying the error message where the Validator controls are placed.

Hope this helps!!

2 Comments

I tried it If I remove the val summary no error message is displayed. Even though I place the validator next to the text box
Have you tried using Display="dynamic" in all the validators?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.