Code excerpt:
<asp:UpdatePanel runat="server" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:ValidationSummary runat="server" DisplayMode="List" />
<asp:GridView ID="MyGridView" runat="server" AllowPaging="true" AllowSorting="true"
DataKeyNames="itemId"
OnRowDataBound="MyGridView_RowDataBound"
onPageIndexChanging="MyGridView_PageIndexChanging"
onSorting="MyGridView_Sorting"
OnRowEditing="MyGridView_RowEditing"
OnRowCancelingEdit="MyGridView_RowCancelingEdit"
OnRowUpdating="MyGridView_RowUpdating"
OnRowDeleting="MyGridView_RowDeleting"
OnRowCommand="MyGridView_RowCommand"
AutoGenerateColumns="false"
onSelectedIndexChanged="MyGridView_SelectedIndexChanged"
CssClass="adminTable">
<Columns>
<asp:TemplateField HeaderText="Name" SortExpression="name">
<EditItemTemplate>
<asp:TextBox ID="editName" runat="server" Text='<%# Bind("name") %>' />
<asp:RequiredFieldValidator runat="server" ControlToValidate="editName"
ErrorMessage="Please enter a Name" Display="None" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="name" runat="server" Text='<%# Bind("name") %>' />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="newName" runat="server" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="newName"
ErrorMessage="Please enter a Name" Display="None" />
</FooterTemplate>
</asp:TemplateField>
<%-- Some additional Similar Templates here --%>
<asp:TemplateField>
<EditItemTemplate>
<asp:LinkButton ID="linkUpdate" runat="server" CausesValidation="true"
CommandName="Update" Text="Save" />
<asp:LinkButton ID="linkCancel" runat="server" CausesValidation="false"
CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="linkEdit" runat="server" CausesValidation="false"
CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="linkDelete" runat="server" CausesValidation="false"
CommandName="Delete" Text="Delete"
OnClientClick="return confirmDelete();" />
</ItemTemplate>
<FooterTemplate>
<asp:LinkButton ID="linkUpdate" runat="server" CausesValidation="true"
CommandName="Insert" Text="Save" />
<asp:LinkButton ID="linkCancel" runat="server" CausesValidation="false"
CommandName="Cancel" Text="Cancel" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
<pagersettings mode="Numeric" position="Top" pagebuttoncount="10" />
<pagerstyle height="30px" verticalalign="Top" horizontalalign="Right" />
</asp:GridView>
<asp:LinkButton ID="LinkAdd" runat="server" OnClick="LinkAdd_OnClick" Text="Add"
CausesValidation="false" />
</ContentTemplate>
</asp:UpdatePanel>
Scenario:
Click the Edit button in any row. The Code-behind OnRowEditing sets MyGridView.EditIndex = e.NewEditIndex; and a couple other small tasks. Edit the Name feild to be blank. Click to save in that row. The appropriate message appears at the top with the validation summary. Now click to Cancel in that row. Nothing happens. Click any
other button anywhere (sort, page, edit in a different row, etc.). Nothing happens.
Everything works as long as all fields stay valid. Also, after the invalid submit, it is possible to type in the edit feild(s), but this does not change the outcomes.
Break points in the various event handlers (i.e. OnRowCancelingEdit, OnRowCommand, OnRowDeleting, etc) shows that no calls are getting to code-behind.
When the GridView is NOT inside an UpdatePanel, everything works as expected. However, it is desired to have these in UpdatePanel so that the page will not “flash” or every page, sort, or edit.
Things tried:
- Changing UpdateMode of the UpdatePanel to both Always and
Conditional. - Removing ChildrenAsTriggers
I got the answer for this from someone outside of SO, and I feel awkward claiming this as my own answer. But if it helps others, I feel I should present it here.
I had to put all my validators and summaries into
ValidationGroups and set all links and buttons toCausesValidation="false". Then, in Code-Behind, at the top of the appropriate methods, callPage.Validate("groupName")and immediatelyreturn;if fails. This forces a post-back which re-sets theUpdatePanel.