如何为多个RequiredFieldValidator仅显示一条消息?

发布于 2024-12-26 06:32:27 字数 281 浏览 5 评论 0原文

如何仅显示多个 RequiredFieldValidator 的单个消息,而不是 RequiredFieldValidator 的单个消息?

我想要如下图所示..

我想要如下图所示..

我的观点是..

< img src="https://i.sstatic.net/kpk9j.png" alt="我的观点是。">

how to display only single message for multiple RequiredFieldValidator instead of individual message for RequiredFieldValidator ?

i want to as shown in following image..

i want to as shown in following image..

my view is..

 my view is.

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

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

发布评论

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

评论(9

二智少女猫性小仙女 2025-01-02 06:32:27

为此,您必须使用 ValidationSummary 控件。请参阅这篇 ValidationSummary 类 MSDN 文章有关如何执行此操作的详细信息和示例。本文包含您想要准确弄清楚的示例。

You will have to use ValidationSummary control for this. See this ValidationSummary Class MSDN article for details and example on how to do this. This article contains an example of what you are trying to figure out exactly.

山色无中 2025-01-02 06:32:27

将 HeaderText 设置为验证摘要中的“(*) 必填字段”之类的内容。

set the HeaderText to something like "(*) Fields are required" to your validation summary.

子栖 2025-01-02 06:32:27

您可以将每个RequiredFieldValidator 的错误消息字段留空,并将* 放入文本字​​段中,然后添加ValidationSummary,使用错误消息定义其标题文本,这将适用于您的场景。

<asp:RequiredFieldValidator ID="RequiredFieldValidator_overhead_name" runat="server" ControlToValidate="TextBox_overhead_name">*</asp:RequiredFieldValidator>


 <asp:ValidationSummary ID="ValidationSummary_overhead_estimate" runat="server" DisplayMode="SingleParagraph" HeaderText="please insert data into fileds" /> 

you can leave error message field of each RequiredFieldValidator blank and put * in text field, then add ValidationSummary defining its header text with error msg this will works for your scenario.

<asp:RequiredFieldValidator ID="RequiredFieldValidator_overhead_name" runat="server" ControlToValidate="TextBox_overhead_name">*</asp:RequiredFieldValidator>


 <asp:ValidationSummary ID="ValidationSummary_overhead_estimate" runat="server" DisplayMode="SingleParagraph" HeaderText="please insert data into fileds" /> 
又怨 2025-01-02 06:32:27

这位先生在这里很简单地解决了这个问题: http://www.cactusoft.com/blog_40

This gentleman solved it here quite simply: http://www.cactusoft.com/blog_40

云淡风轻 2025-01-02 06:32:27

快速简单的方法:将 CssClass 添加到 ValidationSummary,然后添加一个 css 样式,该样式设置该类下的 ul 元素以显示:none。

例如:

<style>
.validationSummary ul {display:none}
<stlye>

...

<asp:ValidationSummary CssClass="validationSummary" ...

Quick and easy way: add a CssClass to the ValidationSummary, then a css style that sets ul elements under that class to display: none.

For example:

<style>
.validationSummary ul {display:none}
<stlye>

...

<asp:ValidationSummary CssClass="validationSummary" ...
雅心素梦 2025-01-02 06:32:27

我可以看到您想要做什么,但是使用 ASP.Net 验证器很难

我能想到的唯一方法是完全删除 ValidationSummary 并使用 ASP.Net 验证器 API 和 JQuery 手动创建您自己的验证器,即

  1. 更改所有必需的验证器 ErrorMessage = "*" 删除文本值
  2. 删除验证摘要
  3. 在底部添加一个标签,用作自定义验证器摘要。将其样式设置为红色
  4. 在页面标记脚本中,类似
if(!Page_IsValid) {    
    $('#myCustomValidatorSummary').text('Please fill in required fields')
}

Page_IsValid 的内容来自 ASP.Net 验证器 API。如果页面验证失败,则设置为 false。

当然,这假设您的表单上只有必需的字段验证器。如果存在混合,那么您将需要通过使用 JQuery/javascript 迭代客户端上的 Page_Validators 来检查一个或多个必需的验证是否失败。

老实说,尽管我不会这样做 - 它是太难了,

我就这样做 - 对于每个必填字段验证器 - 设置

Text="*" 
ErrorMessage="[Field Name] is mandatory. Please supply a value." or similar.

I can see what you are trying to do but it's difficult with the ASP.Net validators

The only way I can think to do it is remove the ValidationSummary altogether and manually create your own using the ASP.Net validator API and JQuery i.e.

  1. Change all required validators to ErrorMessage = "*" Remove Text value
  2. Remove Validation Summary
  3. Add a label at the bottom to function as a custom validator summary. Style it red
  4. In the page markup script something like
if(!Page_IsValid) {    
    $('#myCustomValidatorSummary').text('Please fill in required fields')
}

Page_IsValid is from the ASP.Net validator API. Set to false if the page fails validation.

Of course this assumes that you only have the required field validators on your form. If there is a mix then you will need to check if one or more of the required ones have failed by iterating through the Page_Validators on the client using JQuery/javascript

Honestly though I wouldn't do it - it's too hard

I would just do this - For each required field validator - set

Text="*" 
ErrorMessage="[Field Name] is mandatory. Please supply a value." or similar.
季末如歌 2025-01-02 06:32:27

除了 ValidationSummary 之外,您还应该使用 ASP.NET 中的 ValidationSummary 控件,您还可以使用 Group 属性将控件分成逻辑组。请参阅 http://msdn.microsoft.com/ en-us/library/system.web.ui.webcontrols.validationsummary.aspx 获取大量示例。

You should use the ValidationSummary Control from ASP.NET in addition to ValidationSummary you could also use the Group property to separate controls into logical groups. See http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.validationsummary.aspx for a bunch of examples.

水染的天色ゝ 2025-01-02 06:32:27

使用 ValidationSummary

ValidationSummary 控件用于显示网页中发生的所有验证错误的摘要。

此控件中显示的错误消息由每个验证控件的 ErrorMessage 属性指定。如果未设置验证控件的 ErrorMessage 属性,则不会显示该验证控件的错误消息。

http://asp-net-example .blogspot.in/2008/10/validationsummary-example-how-to-use.html

use ValidationSummary

The ValidationSummary control is used to display a summary of all validation errors occurred in a Web page.

The error message displayed in this control is specified by the ErrorMessage property of each validation control. If the ErrorMessage property of the validation control is not set, no error message is displayed for that validation control.

http://asp-net-example.blogspot.in/2008/10/validationsummary-example-how-to-use.html

じее 2025-01-02 06:32:27

要添加到 Mike Godin 的答案,仅显示多个字段验证器的单个警报消息:

保留单独的必需消息。添加验证摘要,其中 DisplayMode="BulletList" 和 HeaderText="请提供上述所需信息。"

“BulletList”显示模式在验证摘要 DIV 内生成 LI 的无序列表,然后通过样式隐藏 UL - 只有“HeaderText”会显示:

    #validationSummary ul {
        display:none;
    } 

<asp:ValidationSummary 
     id="validationSummary" 
     DisplayMode="BulletList"
     EnableClientScript="true"
     HeaderText="Please provide the required information above."
     ValidationGroup="btnSubmit"
     runat="server"/>

To add to Mike Godin's answer, for only showing a single alert message for multiple field validators:

Keep individual required messages. Add Validation Summary with DisplayMode="BulletList" and HeaderText="Please provide the required information above."

The "BulletList" display mode produces a unordered list of LI's inside the Validation Summary DIV, then hide UL via styling - only the "HeaderText" will show:

    #validationSummary ul {
        display:none;
    } 

<asp:ValidationSummary 
     id="validationSummary" 
     DisplayMode="BulletList"
     EnableClientScript="true"
     HeaderText="Please provide the required information above."
     ValidationGroup="btnSubmit"
     runat="server"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文