I have a GridView defined like this:
<asp:GridView ID='myGridView' ruant='server'> <asp:BoundField DataField='myField' /> <asp:CommandField ShowDeleteButton='true' ShowEditButton='true' /> </asp:GridView>
After I put a row into edit mode with the Edit button, how do I capture the Enter key and trigger the resulting Update on the row? Right now if I hit enter, the page reloads, what was entered into the TextBox is lost, and the row stays in edit mode. I know how to disable the enter key entirely on the form (the current workaround), but I’d like to have it fire the Update command.
Well, using the knowledge from the question you linked, it’s simple:
As we found out in the comments, this introduces a small problem. The
GridView_RowUpdatingserver event does not fire anymore, but the question author relies on it.In short – the server event model relies on the form field
__EVENTTARGETto be set. This form field is not sent when just calling theform.submit(). A solution would be to ‘click’ the relevant button with JavaScript.See ‘Using the enter key to submit a form’ on AllAsp.net, which covers the issue in more detail.