Click here to Skip to main content
15,946,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I never really got the hang of this:

I have a page where the user could add details, but the login control is always there in the top left.

On any professional site, I can enter my login details and hit "enter", but if I don't then "enter" will submit the for I filled out.

How is this done? How do pro sites manage this? Is it based on which control is active (focused) when I hit enter?

Thanks ^_^
Andy
Posted
Comments
Suvendu Shekhar Giri 19-Aug-15 4:26am    
Isn't that refered to as "Default Button"?

Try putting a panel around the login control and set the default button property for the respective button.
At the same time, you can also set default button for the form too.

If your requirement is something different, please share more information.
Andy Lanng 19-Aug-15 6:48am    
Terminology is something autodidacts like me lack :S
This is what I am looking for, but F-ES posted the solution. If I could hand points out to comments then you'd get 5'ed ^_^
Sinisa Hajnal 19-Aug-15 4:27am    
It is either iframe with independant handling of enter or javascript which handles enter key for the page. Google around, you'll find plenty of examples. Good luck.

1 solution

When you press "Enter" on a form the browser will "click" the first button on the form, so if that is your Submit/Login button then people can enter their details and just press enter to login.

If you want a login form and, for example, a search form on the same page then you have two forms. One for login and one for search. That way pressing enter will only trigger the one the user is on.

If this is WebForms and your entire page is wrapped in a single server form (form tag with runat=server) then all your controls are in one form so if your login area has a login button and your search area a search button then clicking enter in the search area will click the login button as it is the first button in your single form. To get around this you wrap your "logical" forms in an asp:Panel and specifiy the default button property on the panel. What this does is cause asp.net to add javascript to your page that hooks into the keypress events and when you press enter it will click the button specified in the default button property of the outer panel. This way when you click enter in login the login button click event is triggered, and when you do it in search the click event of the search button is triggered.
 
Share this answer
 
Comments
Andy Lanng 19-Aug-15 6:46am    
great - just what I was after. It's just one of those things that I have not yet done :S

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