I want to prevent ASP.NET GridView from reacting to the enter button
- by StephaneT
I have an ASP.NET page with a gridview control on it with a CommandButton column with delete and select commands active.
Pressing the enter key causes the first command button in the gridview to fire, which deletes a row. I don't want this to happen. Can I change the gridview control in a way that it does not react anymore to pressing the enter key?
There is a textbox and button on the screen as well. They don't need to be responsive to hitting enter, but you must be able to fill in the textbox. Currently we popup a confirmation dialog to prevent accidental deletes, but we need something better than this.
This is the markup for the gridview, as you can see it's inside an asp.net updatepanel (i forgot to mention that, sorry): (I left out most columns and the formatting)
<asp:UpdatePanel ID="upContent" runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnFilter" />
<asp:AsyncPostBackTrigger ControlID="btnEdit" EventName="Click" />
</Triggers>
<ContentTemplate>
<div id="CodeGrid" class="Grid">
<asp:GridView ID="dgCode" runat="server">
<Columns>
<asp:CommandField SelectImageUrl="~/Images/Select.GIF"
ShowSelectButton="True"
ButtonType="Image"
CancelText=""
EditText=""
InsertText=""
NewText=""
UpdateText=""
DeleteImageUrl="~/Images/Delete.GIF"
ShowDeleteButton="True" />
<asp:BoundField DataField="Id" HeaderText="ID" Visible="False" />
</Columns>
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>