每个文本框单独显示验证​​摘要。在 ASP.NET 网站中

发布于 2024-12-09 05:15:28 字数 670 浏览 1 评论 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; />

我有这个文本框和验证控件。我有很多文本框,每个文本框都是必填字段,我在验证摘要中显示错误消息。我已将验证摘要放置在表单下方。我在表格标签内有文本框和标签。如何在文本框旁边显示错误消息。我必须向下和向上滚动才能找到 req 字段。相反,我想显示在文本框旁边。

 <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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌路终见情 2024-12-16 05:15:28

如果您不想显示验证摘要,则可以将其删除或将“ShowSummary”设置为 false。我个人会这样做,然后将“ShowMessageBox”设置为 true,以便用户收到警报。

警报中显示的文本是您在“RequiredFieldValidator”的“ErrorMessage”中输入的内容。 “RequiredFieldValidator”还有一个名为“Text”的属性。这将成为文本框旁边的错误消息。

<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" />

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" />
灯角 2024-12-16 05:15:28

如果我理解正确,您希望在文本框旁边显示验证错误消息,而不需要在底部显示它们。如果是这样,请从页面中删除 ValidationSummary 控件。这会导致在放置验证器控件的位置显示错误消息。

希望这有帮助!

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!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文