A TextBox
in a web application will cause a TextChanged
event when Enter is pressed, but only if the text has changed.
If the text has not changed when Enter is pressed, a postback still occurs, but the TextChanged
event does not.
I'm wondering if it is possible to determine that Enter was pressed in a textbox and caused the postback, ie. is there something like the following?
protected void Page_Load(object sender, EventArgs e) {
if (sender.reasonControlName == "MyTextBox" &&
sender.reasonControlKey == keyEnter) {
handleEnterKey();
}
}
ASP.Net 4
Note, this is not a question about how to disable the postback caused by ENTER key in a TextBox in a web application, e.g. stackoverflow.com/questions/4209903
There is also a workaround using a panel and DefaultButton stackoverflow.com/questions/12072281, but this seems like a bit of a cludge.