I was going to call this post Blah blah blah: The Maddening, but a lucky dip into forums.asp.net just before I began to write saved my bacon. I now have a fix, and the madness has been reduced to a mere simmer from its former rolling boil.
An ASP.NET AJAX* UpdatePanel on the page, triggered conditionally by a button. A single textbox in the form. Without some way of forcing the button to click when the ENTER key is pressed, the form merely does a postback, not a callback, thus rendering the the entire point of my UpdatePanel COMPLETELY NIL.
Note, in the sample above, that the form's DefaultButton attribute is set to SearchButton. This is the usual way to ensure that pressing ENTER fires the appropriate button click event server-side. And indeed, without an UpdatePanel in the picture, this works as advertised for both IE7 and Firefox.
But. Throw an UpdatePanel and the need to fire a callback into the mix, and Firefox pays no attention, but continues to postback when ENTER is pressed. Only IE7 performs correctly: the button's client-side click event is fired and the callback, not a postback, occurs.
These don't work. Don't waste your time. Either IE will be happy, or Firefox, but not both. (Remember? The Maddening?)
- Add a non-visible textbox to the form, which is a hack only suitable for ensuring the correct server-side event fires. Makes no difference to client-side callback initiation.
- Add a client-side onkeypress event to the textbox to check and see if the ENTER key has been pressed, and if it has, forcibly fire the relevant button's click event.
- Bang your head on the keyboard so hard people on the street stop and compliment you on the QWERTY tattoo.
Set the button's UseSubmitBehavior attribute to false:
Apparently there's a little more monkeying to do if the button is an ImageButton:
* In the name of Cyclopean Cthulhu, couldn't we just have kept calling it by its in-development codename: "Atlas"? It feels like a mouthful of marbles every time I say "ASP.NET AJAX". And I have to write it in all caps? Fwah!