In ASP.NET WebForm, pressing the Enter key on the keyboard in the page will automatically trigger some events, but this is not the effect we want, we can set it to cancel it, so how to deal with it?
1. TextBox will trigger other events when entering the input box, how to solve it?
In ASP.NET WebForm, pressing the Enter key on the keyboard in the page will automatically trigger certain events, but this is not the effect we want, we can set it to cancel it, how to deal with it?
Foreground code:
- Name:
Set the code in Page_Load in the background:
Code example:
//Set the button to trigger any event by pressing Enter txtCategoryName.Attributes["onkeydown"] = "if(event.keyCode==13){return false;}";
2. How to specify the event of the button when the carriage return of the TextBox is triggered?
In ASP.NET WebForm, if you press the Enter key on the keyboard on the page, you need to customize settings to trigger certain events, such as pressing the Enter key to automatically perform query operations.
Code example:
protected override void OnInitComplete(EventArgs e) { base.OnInitComplete(e); // TextBox carriage return triggers custom event method this.txtCategoryName.TextChanged += new EventHandler(btnOrder_Click); }
Original link: https://www.cnblogs.com/kimiliucn/p/17589948.html
Copyright statement: This article is an original article, and the copyright belongs to [Watermelon Programmer]. Please indicate the source for reprinting. If you have any questions, please consult by private message.
Original link: https://www.cnblogs.com/kimiliucn/p/17589948.html