Key Event Handling in Client Side Scripting (JavaScript) in ASP.NET

This practical approach will provide you a way to handle key events in JavaScript in ASP.Net. There are three events associated with key events; they are :
  • onkeyUp
  • onkeyDown
  • onkeyPress
The Script
<script type="text/javascript">
        function getUpper(a)
        { 
            var upper=a.toUpperCase();
            document.forms[0]["TextBox1"].value=upper;
        }
        function getLower(s)
        {
            var lower=s.toLowerCase(); 
            document.forms[0]["TextBox2"].value=lower;
        }
        function CloseTab()
        {
            self.close();
        }
   
</script> 
The Usage
<div>
<table><tbody>
<tr>                 <td style="width: 181px;">  Name in Block Letters :</td>                 <td>  <asp:textbox id="TextBox1" onkeyup="getUpper(this.value);" runat="server"></asp:textbox></td>             </tr>
<tr>                 <td style="width: 181px;">  Name in Small Letters :</td>                 <td>  <asp:textbox id="TextBox2" onkeyup="getLower(this.value);" runat="server"></asp:textbox></td>             </tr>
<tr>                 <td colspan="2">  <asp:button id="Button1" onclientclick="CloseTab()" runat="server" text="Close" width="97px">                  </asp:button></td>             </tr>
</tbody></table>
</div>


 
Your data will be displayed in upper and lower case in the respective textboxes and when you click on the close button the following alert box will displayed.
If you click on yes the window will be closed and if no then the window will not be closed.
Key Event Handling in Client Side Scripting (JavaScript) in ASP.NET Key Event Handling in Client Side Scripting (JavaScript) in ASP.NET Reviewed by Bhaumik Patel on 2:03 AM Rating: 5