Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai
How to use enter key from keyboard to login in web application not use focus().pls reply asap


Regards
Aravind
Posted

Below is the sample code for you. Hope it will help

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1"  runat="server">
    <title>Untitled Page</title>
 
    <script language="Javascript">
 
function CheckKey() {
    switch (event.keyCode) {
    case 13:
    Login();
    break;
    default:
    //nothing
    }
}
 
function Login(){
document.getElementById("btnLogin").click();
}


   </script>

</head>
<body >
    <form id="form1"  runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        
    </div>
    <asp:Button ID="btnLogin" runat="server" Text="Login" />
    </form>
    <script>
document.body.onkeydown=CheckKey();

</script>
</body>
</html>
 
Share this answer
 
v2
Comments
Aravindba 31-May-13 1:31am    
Thanx for ur reply,in web site we have master page,so other than login page all are not having head,body section, so i need above code if i use master page
Mahesh Bailwal 31-May-13 2:01am    
I updated my solution.
You can use below javascript code inside your web form to attach keydown event handler. Make sure to add this script tag at end of your .aspx page.

<script>
document.body.onkeydown=CheckKey();

</script>
Put your login controls inside a Panel and set the DefaultButton property of the panel as your Login Button.
ASP.NET
<asp:Panel runat="server" ID="pnlLogin" DefaultButton="btnLogin">
     Put your login textboxes and buttons here.
</asp:Panel>



--Amit
 
Share this answer
 
v2
ASP.NET
<asp:panel id="p" runat="server" defaultbutton="myButton" xmlns:asp="#unknown">
  <%-- Text boxes here --%>
  <asp:button id="myButton" runat="server" />
</asp:panel>


May this Help You
 
Share this answer
 

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