Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pressing enter on the keyboard triggers the wrong event 2

Status
Not open for further replies.

drew10

Programmer
Feb 26, 2002
123
US
I have a login form with 2 textboxes(1 for username, 1 for password) and a submit button. Also on the form, above the login I have an imagebutton. When the user enters their login information and hits enter on the keyboard, the event for the imagebutton is fired, not the submit button. What am I doing wrong here?

Any help would be greatly appreciated!

-drew10
 
You aren't doing anything wrong. This is simply a capability that .Net doesn't support.

Any button you put on the page is treated like a submit button. This is needed to create the postback loop that Asp.net uses. Since you have more that one button the browser sees multiple submit buttons. Obviously only one can be fired on enter press. The browser chooses the first one on the page and fires that one.

Sorry I couldn't help, currently I haven't found a work around for this so you'll have to work around the problem. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Thanks,
That's what I figured. I've tried to implement an onkeyup javascript function that checks to see if the window.event.keyCode = 13 (the keyCode for the enter button), and then fire the event I want, but due to time restrictions, I gave up and moved the button further down on my page. Everything works fine now.
-Drew
 
glad I could point you in the right direction That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
try this

in your text boxes:
onkeyPress="javascript:pushIt(event);return true;"

in the .aspx file:

function PushIt(e){
if (e.keyCode == 13) {
document.formName.btnName.focus();
}
}
 
Zomb: Your solution works well from textbox to button_click on hitting the "Enter" button on the keyboard. Do you think you could use this technique for moving from textbox to textbox? Or are there restrictions or other limitations?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top