Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1470
Overriding ESC key on control
posted
  • ASP.Net Web Forms.

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.

Parents
No Data
Reply
  • 20255
    Verified Answer
    Offline posted

    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.

Children