Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
when i press ctrl+s it should save into database after get data from registeration.aspx.,
Posted

 
Share this answer
 
Comments
Umapathi K 18-Jun-12 5:34am    
its not working at all.,
look this example

XML
<body onkeypress="HotKeyClick();">

<asp:Button ID="Btn" runat="server" Text="Save"  AccessKey="s" />


in js write this code

C#
function HotKeyClick()
{
    if(event.srcElement.type == 'text' || event.srcElement.type == 'textarea' || event.srcElement.type == 'select') return true;

    var ArrButtons = document.getElementsByTagName('input');

    for(var Count=0; Count < ArrButtons.length; Count++)
    {
        if(ArrButtons[Count].type == 'submit')
        {
            if(ArrButtons[Count].accessKey != null)
            {
                var keyChar = new String(String.fromCharCode(event.keyCode));
                var acsChar = new String(ArrButtons[Count].accessKey);

                if(keyChar.toUpperCase() == acsChar.toUpperCase())
                {
                    if (ArrButtons[Count].disabled == false)
                    {
                        ArrButtons[Count].focus();
                        ArrButtons[Count].click();
                        break;
                    }
                }
            }
        }
    }
}
 
Share this answer
 
Comments
Umapathi K 18-Jun-12 6:31am    
in my page no body tag., i used content place holder., where to write onkeypress="HotKeyClick();
Umapathi K 18-Jun-12 8:12am    
its not working
AccessKey is property to set shortcut key for controls.
XML
<asp:Button AccessKey="S" ID="btnSubmit" runat="server">

Now press ALT + S to trigger the button.

you can use the javascript for the same task: Keyboard Shortcut in ASP.NET[^]

Please refer:
Asp.Net ShortCut Keys[^]
ASP.NET Keyboard Shortcut Controls[^]

[EDIT]

JavaScript and Shortcut Keys[^]
Handling Keyboard Shortcuts in JavaScript[^]
How to create Ctrl+Key shortcuts in Javascript[^]
 
Share this answer
 
v2
Comments
Umapathi K 18-Jun-12 5:36am    
here i given my coding., its not working



<script type="text/javascript" language="javascript">
var isCtrl=false;
document.attachEvent('onclick', KeysShortcut);
function KeysShortcut()
{
if (event.keyCode == 16)
{
isCtrl=true;
}
if (event.keyCode == 113 && isCtrl == true)
{
document.getElementById(ImageButton1).click();
}
}
</script>



<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/images/Login_0.png" önClick="ImageButton1_Click1" ToolTip="Click" />
Prasad_Kulkarni 18-Jun-12 5:37am    
What is this?
Umapathi K 18-Jun-12 5:41am    
in .aspx i used above coding to perform my task
Manas Bhardwaj 18-Jun-12 5:39am    
Good ref +5
Prasad_Kulkarni 18-Jun-12 5:41am    
:) Thank you Manas!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900