I have one UpdatePanel surrounding a asp panel. Inside the panel I have one repeater, two buttons, and two labels. Inside the repeater's ItemTemplate I have an ImageButton and TextBox.
Here is the ASP Code:
1 <asp:UpdatePanel ID="AdvancedSearchUpdatePanel" runat="server" UpdateMode="conditional" RenderMode="block" ChildrenAsTriggers="true">
2 <ContentTemplate>
3 <asp:Panel ID="AdvancedSearchPanel" runat="server" DefaultButton="SubmitSearchButton">
4 <asp:Repeater ID="AdvancedSearchRepeater" runat="server">
5 <HeaderTemplate>
6 <table class="searchButton">
7 <tr>
8 <td colspan="100%">
9 <asp:Label ID="KeywordLabel" runat="server" Text="Search By Keyword" Width="100%" Font-Bold="true"/>
10 </td>
11 </tr>
12 </HeaderTemplate>
13 <ItemTemplate>
14 <tr>
15 <td colspan="100%">
16 <table cellpadding="0" cellspacing="0" style="padding-right:5px">
17 <tr>
18 <td>
20 <asp:ImageButton ID="DeleteCriteriaButton" runat="server" ImageUrl="~/Resources/Images/close.gif" AlternateText="Click to Delete" OnClick="DeleteCriteriaButton_Click" />
21 </td>
22 <td>
23 <asp:TextBox ID="KeywordTextBox" runat="server" Text='<%# Container.DataItem %>' CssClass="keywordSearch" Width="123px" OnTextChanged="KeywordTextBox_TextChanged" />
24 </td>
25 </tr>
26 </table>
27 </td>
28 </tr>
29 </ItemTemplate>
30 <FooterTemplate>
31 </table>
32 </FooterTemplate>
33 </asp:Repeater>
34 <table class="searchButton">
35 <tr>
36 <td>
37 <asp:Button ID="AddAnotherSearchButton" Text="Add Criteria" runat="server" OnClick="AddAnotherSearchButton_Click" />
38 </td>
39 <td>
40 <asp:Button ID="SubmitSearchButton" Text="Submit Search" runat="server" OnClick="SubmitSearchButton_Click" />
41 </td>
42 </tr>
43 <tr>
44 <td colspan="100">
45 <asp:Label ID="ReadableSqlString" runat="server" />
46 </td>
47 </tr>
48 <tr>
49 <td colspan="100">
50 <asp:Label ID="ErrorLabel" runat="server" ForeColor="red"/>
51 </td>
52 </tr>
53 </table>
54 </asp:Panel>
55 </ContentTemplate>
56 </asp:UpdatePanel>
My problem is that the default button for the panel is the SubmitSearchButton.
On the first press of the enter key everything works as it should.
On the second press of the enter key the DeleteCriteriaButton's (ImageButton) event gets fired because it is the first button in the panel.
The only way I have seen to get around this is to put a button before the ImageButton that has a width of zero and have its event call the SubmitSearchButton event and everything works as should.
Does anyone know a cleaner way around this problem or a reason this is happening.
Thanks in advance.