Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends.... i am creating an application of order management system... there i have to use key combination for some of functionalities. how can i call a c# code behind function on pressing ctrl+q
Posted
Comments
F-ES Sitecore 1-Sep-15 10:58am    
google "call javascript on control keys" and "asp.net call server method from javascript" then put the two together.

1 solution

This problem is totally unrelated to forms. Moreover, it is unrelated to C# and ASP.NET. The only relevance to ASP.NET is that you can write/generate JavaScript in ASP.NET code, but all works is done on the client side by JavaScript, no matter what you do. You should handle the event keydown and check the key and key states.

This is the useful resource: http://www.asquare.net/javascript/tests/KeyCode.html[^].

It could be something like this:
JavaScript
window.onkeydown = function(eventInstance) {
    if (
        eventInstance.ctrlKey
        && !eventInstance.shiftKey
        && !eventInstance.altKey
        && !eventInstance.metaKey
        && eventInstance.keyCode == 65)
            alert("Ctrl-A");
}

Not that it works no regardless any controls you may have on the page, even if one holds the keyboard focus. Also note that I checked up that other status keys are not pressed; you can change it.

For testing, I used 'A' instead of 'Q', because 'Q' (81 instead of 65) is often used by browsers for other purposes. But if you want Ctrl+Q, please try using it, or whatever else you want.

—SA
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900