We have the following code in place when a user presses the ESC key we execute a post back to clear our screen:
// capture ENTER and execute Search, ESC and execute Clear. $(document).keypress(function (e) { if (e.which == "13") { //enter <-- Works document.getElementById('MainContent_btnSearch').click(); return false; } if (e.which == "27") { // escape <-- fails when focus is in an Infragistics control. document.getElementById('MainContent_btnClear').click(); return false; } });
It appears that the Infragistics control also uses the ESC to clear the value from the control. Is there a way to prevent/override the Infragistics control from eating the ESC key?
The code handling the Enter key works fine in the same scenario.
Hello Pete,
Thank you for contacting us.
About your findings, yes our controls have there own implementation of ESC key press. In order to handle it you will need to use KeyDown client event, which every our control have. As I see you are using WebTextEditor, so below I am showing simple implementation of this approach especially for WebTextEditor:
<head runat="server"> <title></title> <script type='text/javascript'> function KeyDown(sender, e) { var keyCode = e.get_keyCode(); if (keyCode == 27) { alert("ESC pressed"); } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <ig:WebTextEditor ID="WebTextEditor1" runat="server"> <ClientEvents KeyDown="KeyDown" /> </ig:WebTextEditor> </div> </form> </body> </html>
Looking forward to hearing from you.
Thanks, I changed my original code from using KeyPress to KeyDown and that also worked.
// capture ESC and execute Clear. $(document).keydown(function (e) { if (e.which == "27") { // escape document.getElementById('MainContent_btnClear').click(); e.preventDefault(); return false; } return true; });