Finding the KEYPRESS in ASP.NET with C#
-
currently i m using ASP.NET with C# (.net 2005, 2.0 framework) i have placed a calendar in my webform (calendar from "toolbox --> calendar"). when i press the ESC key, the calendar should get INVISIBLE... how to do this? help me. - KARAN
-
currently i m using ASP.NET with C# (.net 2005, 2.0 framework) i have placed a calendar in my webform (calendar from "toolbox --> calendar"). when i press the ESC key, the calendar should get INVISIBLE... how to do this? help me. - KARAN
-
You could use this and then find the correct key number for esc, i think this one is for when the enter button is pressed if (window.event.keyCode == 13) { calendar.visible - false } hope this helps :)
i cant get the "window.event.keyCode" and where should i write this code?... where it is?
-
i cant get the "window.event.keyCode" and where should i write this code?... where it is?
Hi John Here is an example: Add this script to the head of your page:
<script type="text/javascript">
function setCmdKey(event) {
if (event.keyCode == 27)
document.getElementById('mydiv').style.visibility = 'hidden';
}
</script>and add this as a body:
<body onkeydown="setCmdKey(event);" >
<div id="mydiv" style="padding:50px;background-color:#f00;">Make me disappear</div>
</body>27 is the keycode for the escape key
Declan Bright www.declanbright.com
-
Hi John Here is an example: Add this script to the head of your page:
<script type="text/javascript">
function setCmdKey(event) {
if (event.keyCode == 27)
document.getElementById('mydiv').style.visibility = 'hidden';
}
</script>and add this as a body:
<body onkeydown="setCmdKey(event);" >
<div id="mydiv" style="padding:50px;background-color:#f00;">Make me disappear</div>
</body>27 is the keycode for the escape key
Declan Bright www.declanbright.com
THANKS A LOT MY DEAR!.. i m searching this for long time.. since i thought that we cant handle the SERVER SIDE process (.net calendar) in client side scripting (javascript).. i m not strong in JAVASCRIPT :(
-
Hi John Here is an example: Add this script to the head of your page:
<script type="text/javascript">
function setCmdKey(event) {
if (event.keyCode == 27)
document.getElementById('mydiv').style.visibility = 'hidden';
}
</script>and add this as a body:
<body onkeydown="setCmdKey(event);" >
<div id="mydiv" style="padding:50px;background-color:#f00;">Make me disappear</div>
</body>27 is the keycode for the escape key
Declan Bright www.declanbright.com
s my friend. its help me a lot. but the thing is when i use more than one calendar, problem occuring. i.e... function show_key ( the_key ) { if ( ! the_key ) { the_key = event.keyCode; } if(the_key == 27) { document.getElementById("Calendar1").style.visibility="hidden"; document.getElementById("Calendar2").style.visibility="hidden"; document.getElementById("Calendar3").style.visibility="hidden"; } } help me plz......... - KARAN
-
s my friend. its help me a lot. but the thing is when i use more than one calendar, problem occuring. i.e... function show_key ( the_key ) { if ( ! the_key ) { the_key = event.keyCode; } if(the_key == 27) { document.getElementById("Calendar1").style.visibility="hidden"; document.getElementById("Calendar2").style.visibility="hidden"; document.getElementById("Calendar3").style.visibility="hidden"; } } help me plz......... - KARAN
Since you haven't described what the problem is I will have to guess. Are the 3 calendar controls on the page when you call the javascript? Have they been written out to the browser?, you need to look at the page source to verify this. My guess is that they are not all there so you will have to test for them in the javascript like this:
if(the_key == 27)
{
if(document.getElementById("Calendar1"))
document.getElementById("Calendar1").style.visibility="hidden";
if(document.getElementById("Calendar2"))
document.getElementById("Calendar2").style.visibility="hidden";
if(document.getElementById("Calendar3"))
document.getElementById("Calendar3").style.visibility="hidden";
}Declan Bright www.declanbright.com
-
Since you haven't described what the problem is I will have to guess. Are the 3 calendar controls on the page when you call the javascript? Have they been written out to the browser?, you need to look at the page source to verify this. My guess is that they are not all there so you will have to test for them in the javascript like this:
if(the_key == 27)
{
if(document.getElementById("Calendar1"))
document.getElementById("Calendar1").style.visibility="hidden";
if(document.getElementById("Calendar2"))
document.getElementById("Calendar2").style.visibility="hidden";
if(document.getElementById("Calendar3"))
document.getElementById("Calendar3").style.visibility="hidden";
}Declan Bright www.declanbright.com
thanks bright :-D