2012-10-31 145 views
0

我有一个文本框和一个GridView中的按钮。当按钮被点击时,文本框有验证。然而,当再次点击按钮时,验证事件永远不会被触发。CustomValidation没有发射第二次点击

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

对编辑的验证与预期相同。但不适用于插入按钮。有什么建议么?

回答

0

@TrekStir - 感谢您指出我在正确的方向。

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

1

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

2:您可以尝试将插入的验证组更改为除编辑以外的其他项。

编辑使用ValidatorCallOut与CustomValidator进行ServerSide验证存在问题。

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

+0

是的,有回传。验证不被调用。 – dcinadr

+0

是的,我尝试改变验证组,但它没有奏效。 – dcinadr

+0

我注意到你有显示=“无”验证控件。你使用ValidatorCallout吗?如果不是,你不应该设置显示=“动态”或“静态”。 – TrekStir

相关问题