Setting the DefaultButton property on a form to an ImageButton, LinkButton, or Button with UseSubmitBehavior=false doesn't work on Firefox because the ASP.NET code hooking the Enter key on form submit looks for a "click" method on the button that Firefox does not support.
If you give your button a name attribute, say name='DefaultButton' for example, then throw the following JavaScript in a file that's included on all pages, it'll work. The trick is to define the click method on Firefox's behalf.
setTimeout(function() { init(); }, 0);
// Fixup link buttons for FF
function init()
{
if (document.getElementsByName)
{
var aoElements = document.getElementsByName("DefaultButton");
if (aoElements)
{
for (var i = 0; i < aoElements.length; i++)
{
if (aoElements[i].click == undefined)
{
aoElements[i].click = aoElements[i].onclick;
}
}
}
}
}
Update on 6/9/08:
That fix apparently doesn't work completely, as when you hit <Enter> in a textarea the form is submitted. That's a critical flaw. I didn't want to wholesale replace ASP.NET's WebForm_FireDefaultButton method, but, c'mon, there's only so much tolerance anyone can have for hunting down and working around other people's bugs.
So, here's a tweaked version of the function that fixes default button handling and works across browsers. In order to use this patched function, you need to define it *after* all other JavaScript files and also after <ajaxToolkit:ToolkitScriptManager /> if you happen to be using it.
var __defaultFired;
function WebForm_FireDefaultButton(event, target) {
var element = event.target || event.srcElement;
if (!__defaultFired && event.keyCode == 13 && !(element && (element.tagName.toLowerCase() == "textarea"))) {
var defaultButton;
if (__nonMSDOMBrowser)
defaultButton = document.getElementById(target);
else
defaultButton = document.all[target];
if (typeof(defaultButton.click) != "undefined") {
__defaultFired = true;
defaultButton.click();
event.cancelBubble = true;
if (event.stopPropagation) event.stopPropagation();
return false;
}
if (typeof(defaultButton.onclick) != "undefined") {
__defaultFired = true;
defaultButton.onclick();
event.cancelBubble = true;
if (event.stopPropagation) event.stopPropagation();
return false;
}
}
return true;
}