Database Search Solution
(New Version) Search Control
Free ASP.NET Controls
ASP.NET Media Player Control
Flash Video Player Control
ASP.NET Telecommute Jobs
Free IP Location Lookup
Test .Net Regular Expressions
CSS/Table/DIV Page Layouts
Article Sites Master List
.NET Windows Forms
General .NET Framework
Accepting Credit Cards
Keyboard Shortcut in ASP.NET
Keyboard shortcuts are well known facility in Windows desktop applications. Shortcuts can increase efficiency and usability of your user interface. Although beginners like to use a mouse, that habit usually disappear after some time when user becomes more experienced, because keyboard shortcuts enables faster work. Many Windows applications, including Visual Studio .NET have so called "Expert Mode" when all tool bars and other visuals aids become invisible and user uses keyboard only.
Keyboard shortcuts are not used that much on Web applications. One of the most popular shortcuts used on web pages is using an Enter keyboard key to submit a web form. If you try some search on Google, after you insert a search terms in search text box, you can press Enter key instead of taking a mouse to click on the Search button. Complete research of Enter key issues you can find in Enter Key in ASP.NET tutorial. One more common shortcut on web pages is using a TAB key to move focus between a controls on a web form.
To use shortcuts in your web application, there are some simple solutions, already implemented in HTML. One of them is using of Access Keys.
Access Keys [Alt + Key]
Access keys are common way to enable keyboard shortcuts on your web page. In short, site visitor can press Alt + some key to get a button clicked or get focus to some textbox. Both ASP.NET 1.1 and ASP.NET 2.0 provide AccessKey property for buttons and text boxes. ASP.NET 2.0 has additional AssociatedControlID property, used in Label control to specify which control will be clicked or get focus.
Access Keys ASP.NET 1.1 example (also works in ASP.NET 2.0):
Access Keys ASP.NET 2.0 example
So, in example above, button btnWonderful will be clicked when ALT + W is pressed.
You should avoid keys reserved by Web browser. Internet Explorer 6 uses F, E, V, T and H to open File, Edit, View, Tools and Help menu items. Firefox uses additional G and B to call its Go and Bookmark menus.
More advanced shortcuts, using Ctrl, Alt and Shift
First, I added handlers for keydown and keyup events and declare variables for storing state of keys:
document.onkeydown = KeyDownHandler;
var CTRL = false;
Second important thing, is to add functions KeyDownHandler and KeyUpHandler:
Finnaly, place state of the keys to variables, using DetectKeys function:
function DetectKeys(KeyCode, IsKeyDown)
Shortcut Enabled ASP.NET Custom Controls
To speed up implementation and go really professional, you can use Bean Software Keyboard Shortcut Controls. With these controls you can in no time add simple or more complex keyboard shortcuts (e.g. Ctrl + Shift + O) in your web application, without need to write any code. Source code is included.
comments powered by Disqus