My login form has 4 controls. The user can input name, password and enter on button for login.
I'd like the Enter key to trigger the Login action after the Name and Password textboxes are filled out.
How can this be done? Trying to avoid btnLogin.Focus()
under the TextBox event.
To trigger a click button on ENTER key, We can use any of the keyup(), keydown() and keypress() events of jQuery. keyup(): This event occurs when a keyboard key is released. The method either triggers the keyup event, or to run a function when a keyup event occurs.
HTML Press the enter key inside the textbox to activate the button. Show activity on this post. By default, browsers will interpret Enter as submitting a form. <button> by default is type "submit" and accesses whatever is located in the form's action attribute (overridden if button's formaction is present).
Solution 1function (event) { if (event. which == 13 || event. keyCode == 13) { //code to execute here return false; } return true; }); Implement it according to your need.
On your form you can set the AcceptButton property to the login button.
Set the form's AcceptButton property to be the Login button. When the user hits Enter, the Click event for that button will be triggered. The CancelButton property is the one you want for your Cancel button.
Again, these are properties of the Form, not the buttons.
private void txtCost_KeyUp(object sender, KeyEventArgs e)
{
//MessageBox.Show(Convert.ToString(e.KeyValue));
if (e.KeyValue == 13)
{
command;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With