Is is possible to exit the edit mode in a Gridview using JavaScript when a key (ex. ESC) is pressed?
Thank you
Is is possible to exit the edit mode in a Gridview using JavaScript when a key (ex. ESC) is pressed?
Thank you
You can catch the escape key press using JavaScript, check this answer: How to detect escape key press with JavaScript or jQuery? (using JQuery)
The switch out of the GridView's edit-mode has to happen on the server side, so you need to invoke a post-back from JavaScript. An easy way to do this is adding a normal ASP.Net button to your page, hiding it with CSS, and then invoking it's click method using JQuery.
Sample:
<asp:Button id="btnPostBackHook" runat="server" onClick="MyServerSidedMethod" style="display: none;" />
<script type="text/javascript">
$(document).keyup(function(e) {
if (e.keyCode == 27) {
$('#<%=btnPostBackHook.ClientID%>').click();
}
});
</script>