Click here to Skip to main content
15,879,326 members
Articles / Web Development / ASP.NET

ASP.NET HotKeys

Rate me:
Please Sign up or sign in to vote.
2.38/5 (7 votes)
3 Feb 2006CPOL 46.4K   434   19   8
How to support HotKeys in your ASPX pages [keyboard + ASPX].

Sample Image - ASPNET_HotKeyasp.gif

Introduction

This article shows how to support HotKeys in your ASPX pages.

The steps involved

Step 1

Open VS.NET and create a new ASP.NET Web Application project.

Sample Image - ASPNET_HotKeyasp_6.gif

Step 2

Add two web forms: aspxMain.aspx and aspxFunction01.aspx.

Sample Image - ASPNET_HotKeyasp_7.gif

Step 3

As the following screenshot shows, add a Label and three Buttons on aspxMain.aspx.

Sample Image - ASPNET_HotKeyasp_8.gif

Step 4

Add a Label and a Button on aspxFunction01.aspx.

Sample Image - ASPNET_HotKeyasp_9.gif

Step 5

Double-click on Button1 of aspxMain.aspx to change the IDE view to the aspxMain.aspx.cs editor and paste the following code in the editor:

C#
Response.Redirect("aspxFunction01.aspx");

Step 6

Edit the code inside aspxMain.aspx, and add the following to the bottom of the editor:

JavaScript
<SCRIPT LANGUAGE="Javascript">
<!--
function Even() {
key = event.keyCode;

switch(key) {
case 33:
var b = document.getElementById("Button1");
b.click();
break;
case 64:
var b = document.getElementById("Button2");
b.click();
break;
case 35:
ver b = document.getElementById("Button3");
b.click();
break;
}
}

document.onkeypress = Even;
-->
</SCRIPT> 

Step 7

Double-click on Button1 of aspxFunction01.aspx to switch the IDE view to aspxFunction01.aspx.cs and paste the following:

C#
Response.Redirect("aspxMain.aspx");

Step 8

Edit the code inside aspxFunction01.aspx, and add the following to the bottom of the editor:

JavaScript
<SCRIPT LANGUAGE="Javascript">
<!--
function Even() {
    key = event.keyCode;

    switch(key) {
    case 41:
        var b = document.getElementById("Button1");
        b.click();
        break;
}
}

document.onkeypress = Even;
-->
</SCRIPT>

Step 9

Test to see whether the project meets your needs or not.

Feel free to let me know your feedback.

License

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


Written By
Software Developer
Singapore Singapore
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Generalclick method Pin
doyang6-Aug-06 19:16
doyang6-Aug-06 19:16 
GeneralThank you YU-TIEN Pin
JohnnyAdams10-Feb-06 16:54
JohnnyAdams10-Feb-06 16:54 
GeneralPlease learn to write in english first Pin
rbastos30-Jan-06 15:32
rbastos30-Jan-06 15:32 
GeneralRe: Please learn to write in english first Pin
YuTien30-Jan-06 18:43
YuTien30-Jan-06 18:43 
GeneralRe: Please learn to write in english first Pin
E. Anderson21-Feb-11 10:35
E. Anderson21-Feb-11 10:35 
Joke[Message Removed] Pin
Mojtaba Vali4-Feb-06 5:47
Mojtaba Vali4-Feb-06 5:47 
GeneralRe: Please learn to write in english first Pin
manchadvaca19-Jan-12 13:14
manchadvaca19-Jan-12 13:14 
Jokeoh sh*t Pin
nguyen Ngoc Tuan23-Jan-06 4:04
nguyen Ngoc Tuan23-Jan-06 4:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.