Hotkey in asp.net page

  • Thread starter Thread starter Billy Zhang
  • Start date Start date
B

Billy Zhang

I want to have following hotkey used in asp.net application, how to do this
especially for F5?

ESC
F3
F4
F5
F6
F9
F10
F12
Ctrl+J

Thanks,
-Billy zhang
 
Hi Billy,

As for web application, the key press/down events are handled by
client-side javascript. And you can register "onKeyDown", "onKeyPress"
script event for the <body> element or any other sub container(such as div
, span....). Here are some web articles mentioned this:

#Code Samples : Make Any Key A Hot Key
http://www.15seconds.com/howto/pg000086.htm

#How to Prevent Users to Press F5 key (Refresh button)
http://anujkrathi.blogspot.com/2007/06/how-to-prevent-users-to-press-f5-key.
html

here is a simple test page I've used for demonstration:

=======================
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function hotkey(eventname)
{

if(eventname.keyCode == 116 )
{
alert("\nyou've pressed F5");

eventname.keyCode =505;// reset key code

return false; //return false to prevent refresh page
}

return true;
}


</script>
</head>
<body onkeydown="return hotkey(event);">
...................
============================

And for complete key code list in javascript key event, here is a good
reference:

#JavaScript KeyCodes List
http://www.aspdotnetfaq.com/Faq/What-is-the-list-of-KeyCodes-for-JavaScript-
KeyDown-KeyPress-and-KeyUp-events.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 
Thanks for your reply Billy,

It seems the "html" extension is broken (by the line break):

the complete url is:

http://anujkrathi.blogspot.com/2007/06/how-to-prevent-users-to-press-f5-key.
html

http://............/how-to-prevent-users-to-press-f5-key.html

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
From: =?Utf-8?B?QmlsbHkgWmhhbmc=?= <[email protected]>
References: <[email protected]>
 
Back
Top