views:

1689

answers:

2

I have a link button on the page and set it as default button, It works fine in IE but not working in Mozila Firefox. Does anybody have any clue how to resolve this issue?

+2  A: 

I had this kind of issue with FF3 and ASP.NET linkbuttons. This seems to be a bug with FF3 (not sure), but the script that fixed is given below:

var __defaultFired = false;

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 (defaultButton) {
            if(typeof(defaultButton.click) != "undefined")
                defaultButton.click();
            else
                eval(unescape(defaultButton.href.replace("javascript:", "")));

            event.cancelBubble = true;

            if (event.stopPropagation) event.stopPropagation();
            return false;
        }
    }
    return true;
}

Keep it at the end of the page so that it overrides the WebForm_FireDefaultButton method rendered by ASP.NET.

Kirtan
@Kirtan work only first time... ANy suggestion why?
Pandiya Chendur
A: 

work only first time we press enter in textbox. After adding some text in textbox and then pressing enter ,default button will not fire.

rakesh