ASP.NET Link Enter key with buttons?
asp.net, c#, event-handling, webforms
Solution
It looks like you're using Web Forms.
You can wrap what you're doing inside of a `Panel` and set the `DefaultButton` property inside of the panel.
<asp:Panel ID="LoginPanel" runat="server" DefaultButton="btLogin">
<asp:TextBox ID="txtUser" runat="server" />
<asp:TextBox ID="txtPass" runat="server" />
<asp:Button ID="btLogin" runat="server">Login</asp:Button>
</asp:Panel>
When the user has entered data in either `txtUser` and `txtPass` and then hit the Enter key, they will trigger the button `btLogin`.
Problem
I stumbled across a little problem with an ASP.NET Web Application. I got a couple buttons on my page that I want to access by pressing my Enter key (Depending on which `TextBox` is focused). Googled helped me, I thought, but no. This is what I found: ``` tbEmail.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('" + btRegister.UniqueID + "').click();return false;}} else {return true}; "); ``` Source This does not seem to work, it still presses another button that I do not want to be pressed at this moment. Any suggestions?