0

I have text box and a button in a gridview. The textbox has validation when the button is clicked. However the validation event never gets fired when the button is clicked a second time.

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

The same validation for edit works as expected. But not for the Insert button. Any suggestions?

2 Answers 2

1

1: Did you set the breakpoint to make sure there is a postback? Is the serverside validation called at all or not?

2: Can you try changing the ValidationGroup for Insert to something else than the Edit.

Edit There are issues using ValidatorCallOut with CustomValidator with ServerSide Validation.

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

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

Here's another way showing error in a jquery dialog: 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

Sign up to request clarification or add additional context in comments.

4 Comments

Yes there is a postback. Validation is not called.
And yes I tried changing the ValidationGroup but it did not work.
I noticed you have Display="None" for validatorcontrol. Are you using ValidatorCallout? If not shouldn't you be setting Display="Dynamic" or "Static".
Yes I am using a validator callout.
0

@TrekStir - thanks for pointing me in the right direction.

The problem was that there was code to make the footer invisible after a row was added. For some reason that was causing the validation code not to fire. I figured out a way to implement the functionality without setting the footer to invisible and this solved the problem.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.