【问题标题】:CustomValidation not firing on second clickCustomValidator 未在第二次单击时触发
【发布时间】:2012-10-31 00:03:32
【问题描述】:

我在网格视图中有文本框和按钮。单击按钮时,文本框具有验证。但是,当第二次单击按钮时,验证事件永远不会被触发。

<asp:GridView ID="ChapterGridView" 
               EnableSortingAndPagingCallbacks="false" 
               AllowSorting="false" 
               AllowPaging="false" 
               runat="server"                            
               AutoGenerateColumns="False" 
               CellPadding="2" 
               ForeColor="#333333"
               GridLines="None"  
               Width="780px" 
               OnRowCommand="ChapterGridView_OnRowCommand" 
               ShowFooter="False" 
               AutoGenerateDeleteButton="true"
               AutoGenerateEditButton="true"
               onrowediting="ChapterGridView_RowEditing"
               onrowdeleting="ChapterGridView_RowDeleting" 
               onrowcancelingedit="ChapterGridView_RowCancelingEdit" 
               onrowupdating="ChapterGridView_RowUpdating"
               onrowupdated="ChapterGridView_RowUpdated"
               DataKeyNames="ChapterId"
               ValidationGroup="ChapterValidation"
               Visible="true">
            <FooterStyle BackColor="#eeeeee" Font-Bold="True" ForeColor="White" />
            <Columns>
                <asp:TemplateField HeaderText="*End Page" HeaderStyle-HorizontalAlign="Left">
                    <ItemTemplate><%# Eval("EndPage")%></ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="EndPage" runat="Server" Text='<%# Eval("EndPage") %>'></asp:TextBox>
                        <asp:CustomValidator ID="TotalPagesValidator" ValidationGroup="ChapterValidation" OnServerValidate="TotalPages_ServerValidate" EnableClientScript="false" ErrorMessage="Number of pages in chapter are greater than number of pages in entire publication." Display="None" ControlToValidate="EndPage" runat="server" />
                    </EditItemTemplate>
                    <FooterTemplate>
                        <asp:TextBox ID="EndPage" runat="Server"></asp:TextBox>
                        <asp:CustomValidator ID="TotalPagesValidator2" ValidationGroup="ChapterValidation" OnServerValidate="TotalPages_ServerValidate" EnableClientScript="false" ErrorMessage="Number of pages in chapter are greater than number of pages in entire publication." Display="None" ControlToValidate="EndPage" runat="server" />

                        <asp:Button ID="btnInsert" runat="Server" Text="Insert" CommandName="Insert" UseSubmitBehavior="false" ValidationGroup="ChapterValidation" /></span>
                    </FooterTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

编辑的相同验证按预期工作。但不适用于“插入”按钮。有什么建议吗?

【问题讨论】:

    标签: asp.net validation customvalidator


    【解决方案1】:

    1:您是否设置了断点以确保有回发?是否调用了服务器端验证?

    2:您可以尝试将 Insert 的 ValidationGroup 更改为 Edit 以外的其他内容吗?

    编辑在使用带有服务器端验证的 CustomValidator 的 ValidatorCallOut 时存在问题。

    http://forums.asp.net/t/1054676.aspx

    http://programminginhell.wordpress.com/2008/08/03/hello-world/

    这是在 jquery 对话框中显示错误的另一种方式:http://weblogs.asp.net/gurusarkar/archive/2011/03/28/part-3-showing-asp-net-server-side-messages-in-a-custom-dialog-server-side-with-asp-net-ajax.aspx

    【讨论】:

    • 是的,有回发。不调用验证。
    • 是的,我尝试更改 ValidationGroup 但它不起作用。
    • 我注意到您有 Display="None" 用于验证器控件。你在使用 ValidatorCallout 吗?如果不是,您不应该设置 Display="Dynamic" 或“Static”。
    • 是的,我正在使用验证器标注。
    【解决方案2】:

    @TrekStir - 感谢您为我指明正确的方向。

    问题是有代码在添加一行后使页脚不可见。由于某种原因导致验证代码不触发。我想出了一种在不将页脚设置为不可见的情况下实现该功能的方法,这解决了问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-13
      • 2018-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多