formview 中的 ASP.NET 验证摘要不起作用

发布于 2024-10-14 09:48:47 字数 1831 浏览 11 评论 0原文

我在 asp.net formview 中有一个验证摘要,而验证器似乎没有触发验证摘要。

我已经尝试过的事情:

  • 在所有内容上启用 ViewState。
  • 将 ClientID 设置为静态。
  • 将所有验证器和摘要上的 ValidationGroup 设置为同一组。
  • 使用Google搜索解决方案。

有人对如何处理这个问题有任何想法吗?

代码。 Formview 声明:

<asp:FormView ID="FormViewPerson" runat="server" DataSourceID="ObjectDataSourcePerson"
    DefaultMode="Edit" OnItemUpdating="FormViewPerson_ItemUpdating" OnItemCommand="FormViewPerson_ItemCommand"
    OnItemUpdated="FormViewPerson_ItemUpdated" Width="100%">

任何带有验证器的文本框:

<td>  <asp:TextBox ID="NumberTextBox" runat="server" Text='<%# Bind("Number") %>' 
                        TabIndex="10" CausesValidation="True" ClientIDMode="Static" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidatorNumber" runat="server" ControlToValidate="NumberTextBox"
                        ErrorMessage="Number is Required" ForeColor="Red" 
                        ValidationGroup="EditPerson">*</asp:RequiredFieldValidator>
                </td>

和提交按钮:

<asp:ValidationSummary ID="ValidationSummaryPerson" runat="server" 
            ForeColor="Red" ClientIDMode="Static" CssClass="validation" 
            ShowMessageBox="True" ValidationGroup="EditPerson" ViewStateMode="Enabled"
            />
        <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
            Text="Save" ValidationGroup="EditPerson" CssClass="ButtonStyle" TabIndex="90" />
        &nbsp;<asp:Button ID="EditCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
            Text="Cancel" CssClass="ButtonStyle" TabIndex="100" 
            ValidationGroup="EditPerson" />

I have a validation summary inside a asp.net formview and the validators just don't seem to trigger the validation summary.

Things I already tried:

  • Enable the ViewState on everything.
  • Set the ClientID to static.
  • Set the ValidationGroup to the same group on both all validators and the summary.
  • Used Google to search for a solution.

Anyone has any ideas on how to handle this?

Code. Formview declaration:

<asp:FormView ID="FormViewPerson" runat="server" DataSourceID="ObjectDataSourcePerson"
    DefaultMode="Edit" OnItemUpdating="FormViewPerson_ItemUpdating" OnItemCommand="FormViewPerson_ItemCommand"
    OnItemUpdated="FormViewPerson_ItemUpdated" Width="100%">

Any of the textboxes with the validator:

<td>  <asp:TextBox ID="NumberTextBox" runat="server" Text='<%# Bind("Number") %>' 
                        TabIndex="10" CausesValidation="True" ClientIDMode="Static" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidatorNumber" runat="server" ControlToValidate="NumberTextBox"
                        ErrorMessage="Number is Required" ForeColor="Red" 
                        ValidationGroup="EditPerson">*</asp:RequiredFieldValidator>
                </td>

And the submitbutton:

<asp:ValidationSummary ID="ValidationSummaryPerson" runat="server" 
            ForeColor="Red" ClientIDMode="Static" CssClass="validation" 
            ShowMessageBox="True" ValidationGroup="EditPerson" ViewStateMode="Enabled"
            />
        <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
            Text="Save" ValidationGroup="EditPerson" CssClass="ButtonStyle" TabIndex="90" />
         <asp:Button ID="EditCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
            Text="Cancel" CssClass="ButtonStyle" TabIndex="100" 
            ValidationGroup="EditPerson" />

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

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

发布评论

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

评论(2

败给现实 2024-10-21 09:48:47

希望按钮的 CausesValidation 设置为 true。

Hope the CausesValidation for the button is set to true.

三生殊途 2024-10-21 09:48:47

好吧,我解决了这个问题。如果其他人遇到此问题,请尝试以下操作:

  • 确保整个表单上只有一 (1) 个验证组。
  • 在提交按钮上将“causesvalidation”设置为“true”。
  • 检查、双重检查和三次检查所有相关控件上的validationgroup属性的拼写。
  • 请留意客户端脚本中的 JavaScript 错误。它们可能会造成严重破坏。

Well, I fixed the issue. If anyone else encounters this problem try the following:

  • Ensure there is only one (1) validation group on the entire form.
  • Set "causesvalidation" to "true" on the submitbutton.
  • Check, double check and triple check the spelling of your validationgroup property on all relevant controls.
  • Be on the lookout for javascript errors in your client-side scripts. They can cause havoc.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文