Binding keyboard shortcut in Asp.Net

Hi,

 

Many a times when working with the Web Application you would like to give the user the comfort of getting the job done without using the mouse. It can be of great use to the user if they can perform many tasks using the keyboard in a web application. If you have used Gmail you would know how easy it can be to select mails using some key.  This feature can be implemented in Asp.net also very easily.

 

In my example I will talk about how to link a key button with the click event of a button. What we will do is bind the keyboard shortcut to the click event of a button, hence the task will be performed on both keyboard click and mouse click of the button.

 

document.attachEvent('onkeyup', KeysShortcut);

 

// Now we need to implement the KeysShortcut
function KeysShortcut ()

{

     if (event.keyCode == 49)

     {  
       document.getElementById('<%= button1.ClientID %>').click();

     }

}

 

Now when the user click on the key 1 the click event of the button1 will be fired.

 

Vikram

Published Wednesday, March 05, 2008 8:09 AM by vik20000in
Filed under: , ,

Comments

# re: Binding keyboard shortcut in Asp.Net

Wednesday, March 05, 2008 4:14 AM by pho

using .click() doesn't just work in every browser. you can use Page.GetPostBackClientReference(button1, '') which emulates a postback from button1. this is the better way to do it...

# re: Binding keyboard shortcut in Asp.Net

Friday, June 12, 2009 1:37 PM by Ambuj Saxena

I have a frameset, having two frames, left frame shows a pdf document, according to the selection in right frame,

before my shortcuts were working, when i was using iframe, but pdf was not showing in that. But in frameset my shortcuts are not working... so how to handle shortcuts at frame level.

# re: Binding keyboard shortcut in Asp.Net

Tuesday, December 22, 2009 11:14 PM by Pedro Luis Angel

I need one demo. publish one demo please in this page

# re: Binding keyboard shortcut in Asp.Net

Thursday, February 04, 2010 12:25 PM by livina

it works! but i need F1 as shortcut, but it always running into help.... can anyone tell me why?

Leave a Comment

(required) 
(required) 
(optional)
(required)