• http://www.techneurons.com/career/
  • experienced programming consultants for hire !!!

    Contact Now

    ASP.NET Support

    Shortcut Keys in Asp.Net

    Posted by Anirudh Krishan Vaishnav on Mar 29, 2010
    Sir,
    I want to use shortcut keys like windows programming in Asp.Net(C#) . Like if i want to click on a link "Home" then i would press (Ctrl+h) or F1/F2/F3 anykey. i think its the metter of client side scripting ?

    Waiting 4 Quick Response.

    Anirudh Krishan Vaishnav
    Replied by consultsarath on Mar 30, 2010
    <p>You can use a simple javascript function. You need to refer to table to Javascript Key Codes for finding the code for each required key. The script function would be as follows:</p> <div style="line-height: normal"><span style="font-family: 'Courier New'; color: blue; font-size: 9pt">&lt;</span><span style="font-family: 'Courier New'; color: #a31515; font-size: 9pt">head</span><span style="font-family: 'Courier New'; font-size: 9pt"> <span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;&gt;</span></span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp; <span style="color: blue">&lt;</span><span style="color: #a31515">title</span><span style="color: blue">&gt;&lt;/</span><span style="color: #a31515">title</span><span style="color: blue">&gt;</span></span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp; <span style="color: blue">&lt;</span><span style="color: #a31515">script</span> <span style="color: red">type</span><span style="color: blue">=&quot;text/javascript&quot;&gt;</span></span></div> <div style="line-height: normal">&nbsp;</div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">function</span> listenKeys(e) {</span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e = e || window.event;</span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">var</span> code;</span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">if</span> (e.which)</span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; code = e.which;</span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">else</span></span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; code = e.keyCode;</span></div> <div style="line-height: normal">&nbsp;</div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">// Write you conditions here</span></span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">// You can check with or without modifiers - ctrlKey, shiftKey, altKey</span></span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: green">// This is just an implementation of Ctrl+S</span></span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">if</span> (e.ctrlKey &amp;&amp; code == 83)</span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.getElementById(<span style="color: #a31515">'&lt;%=lbHome.ClientID %&gt;'</span>).click();</span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; font-size: 9pt">&nbsp;&nbsp;&nbsp; <span style="color: blue">&lt;/</span><span style="color: #a31515">script</span><span style="color: blue">&gt;</span></span></div> <div style="line-height: normal"><span style="font-family: 'Courier New'; color: blue; font-size: 9pt">&lt;/</span><span style="font-family: 'Courier New'; color: #a31515; font-size: 9pt">head</span><span style="font-family: 'Courier New'; color: blue; font-size: 9pt">&gt;</span></div> <p>You can attach this function to the <strong>onload</strong> event of <strong>body</strong>.</p> <div style="margin: 0cm 0cm 10pt"><span style="line-height: 115%; font-family: 'Courier New'; color: blue; font-size: 9pt">&lt;</span><span style="line-height: 115%; font-family: 'Courier New'; color: #a31515; font-size: 9pt">body</span><span style="line-height: 115%; font-family: 'Courier New'; font-size: 9pt"> <span style="color: red">onkeydown</span><span style="color: blue">=&quot;listenKeys();&quot;&gt;</span></span></div>
    We are experts in Cloud Computing Technologies. We can assist you to build high scalable business applications using Amazon Web Services (Amazon EC2, Amazon S3, Amazon SES, SNS, CloudFront), Windows Azure Platforms - Windows Azure and SQL Server Azure, Google App Engine using Python and Django Framework. We are Expert Programming Consultants available at affordable rates per hour. We work on several technologies - .NET, Python, Google App Engine, PHP, Windows Azure, Amazon Web Services ...