Dear experts,

I have a GridView with an invisible CancelEdit button. I want to use this button to get out of Edit mode. When I make this button visible for testing purposes and press it with the mouse, it works fine, getting me out of Edit mode. But I need to get out of Edit mode on pressing Esc key. I use a javascript function for this. But though the CancelEdit button is found, .click() doesn't do anything, and I still in Edit mode. Could you help me on this, please? Here is my code:

function keyPressHandler(e) {
            var kC = (window.event) ?    // MSIE or Firefox?
                 event.keyCode : e.keyCode;
            var Esc = (window.event) ?
                27 : e.DOM_VK_ESCAPE;    // MSIE or Firefox
            if (kC == Esc) {
                try {
                    document.getElementById('<%=((FrontListGridView.EditIndex > -1)?(FrontListGridView.Rows[FrontListGridView.EditIndex].Cells[1].FindControl("CancelEdit").ClientID):string.Empty) %>').click();
                catch (e) {


                            <asp:Button ID="CancelEdit" runat="server" CommandName="Cancel" />  
In Page_Load():
Page.ClientScript.RegisterStartupScript(typeof(Page), "escscript", "document.onkeypress=keyPressHandler;", true);
8 Years
Discussion Span
Last Post by dpreznik

I don't think you can get out of the box (Browser window). I believe that for securely reasons you can't track any of the keyboard clicks through a browser.


Actually, I can. When I debug in Firebug, I can see that the code is executed. E.g. I can show alert(), if I place it instead of button click. Moreover, it works in IE. I have a problem only in Firefox.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.