Click here to Skip to main content
15,887,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my login page,after giving userid and password how to login using enter key instead of using login button?
How to move the control from textbox to button when i press enter key?
Posted

You need a submit button with default focus on it. For that, you need to add "DefaultButton" property for the page.

In ASP.NET 2.0 onwards, it's said to have "Default Button" defined for the page. By simply specifying the "defaultbutton" property to the ID of the <asp:Button>, whose event you want to fire, your job is done.
The defaultbutton property can be specified at the Form level in the form tag as well as at panel level in the <asp:panel> definition tag. The form level setting is overridden when specified at the panel level, for those controls that are inside the panel

Sample example:
<form id="Form1"
    defaultbutton="SubmitButton"
    defaultfocus="TextBox1"
    runat="server">


Refer:
ASP.NET DefaultButton Property[^]
Sample usage of Default button[^]

No need of any key code or so. Using above, default behavior of enter press would direct it as defined for that button click.
 
Share this answer
 
Comments
comeshyamala 27-Jun-12 4:59am    
Thank You so much...Its working....
Sandeep Mewara 27-Jun-12 5:12am    
Welcome.
Member 9084528 27-Jun-12 5:02am    
THANK YOU SO MUCH
IT IS WORKING.....
Sandeep Mewara 27-Jun-12 5:12am    
Welcome.
Uday P.Singh 27-Jun-12 5:12am    
5!
Hi,
You have to do the coding in the textbox1_KeyDown Event

C#
Public void textbox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        //Your Code
        //Button Click event code
    }
}


Hope this will help you.
 
Share this answer
 
Comments
Member 9084528 27-Jun-12 3:45am    
Thanks...I have tried but one error is coming like:

Type or namspace name KeyEventArgs cannot be found...missing assembly or directive
Member 9084528 27-Jun-12 3:45am    
pls help to resolve this error..
Soft009 27-Jun-12 3:55am    
Can you send me your code.
Is your application web base or windows base
Soft009 27-Jun-12 4:08am    
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{

}
}

Is your code like this
This is in C# you have to convert it into vb.net
Sandeep Mewara 27-Jun-12 4:36am    
OP is asking for ASp.NET. What you suggested is Winforms.

See my 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