ASP.NET: How to specify which button should defaultly react for an Enter press?
Posted
by agnieszka
on Stack Overflow
See other posts from Stack Overflow
or by agnieszka
Published on 2010-04-06T14:24:01Z
Indexed on
2010/04/06
14:33 UTC
Read the original article
Hit count: 239
ASP.NET
|JavaScript
I have a webpage where there are two buttons and a textbox. When the page loads and user presses enter, the first button is clicked - and that is ok.
I would like to assure that if user enters the textBox and types anything there and THEN presses enter, the second button is clicked. When I enter the textBox I can tell that the first button will be used when I press enter, because it is a bit dark-blue-bordered then.
I tried javascript's
if (event && event.keyCode == 13)
document.getElementById("Button2").click();
but it somehow doesn't work. So my second thought was that there must be a possibility to tell the browser which button should defaultly react for an enter press when I'm in a specific textBox (the dark-blue-bordered button).
Edit: it might matter that first button is input and the second one is asp:Button
© Stack Overflow or respective owner