There is a TextBox text box on the ASPX page, and there are three button buttons. Enables the TextBox's TextChanged event and the button's Click event.
Problem:
The TextChanged event is now triggered when the TextBox text box has entered the data by pressing "enter", but it also triggers the Click event of the First button button on the page.
Workaround One:
When you hit enter in the text box, the form is submitted. Because a page in. NET has only one form form. So there is a sumbit event.
When the Usesubmitbehavior property is true, the form's commit triggers this event.
The order is to trigger the Click event First and then trigger the button's click time of Usesubmitbehavior to true.
Of course, if there are multiple buttons, the first button event is triggered by default.
To resolve this problem, change the Usesubmitbehavior to false. (When multiple buttons, the Usesubmitbehavior is all changed to false.) )
Workaround Two:
(When you want to use the button's OnClientClick pop-up Confirmation window, if Usesubmitbehavior is false, regardless of what you choose not to execute the server button's onclick code, this time you need to use the workaround two)
The solution comes from the e-chapter of Mencius:
private void Page_Load (object sender, System.EventArgs e)
{
TextBox1.Attributes.Add ("onkeydown", "if (event.keycode==13) {This.blur (); return false}");
}
private void Button1_Click (object sender, System.EventArgs e)
{
Response.Write ("button");
}
private void textBox1_TextChanged (object sender, System.EventArgs e)
{Response.Write (TextBox1.Text);
}
(Ensure that the AutoPostBack property of TextBox1 is true, as long as it is set to true, the above code is not required to resolve the problem.) )
Alternatively, you can set the client Id.focus () or set the TabIndex property.
ASP. NET enter the OnClick event solution that triggers the button