Link on the page and set it as the default button, work fine in IE, but not in Mozila

I have a link button on the page and set it as the default button, it works fine in IE, but doesn't work in Mozilla Firefox. Does anyone know how to solve this problem?

+3
source share
5 answers

I had such a problem with FF3 and ASP.NET channels. This seems to be a bug with FF3 (not sure), but a fixed script value 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;
}

Store it at the end of the page so that it overrides the method WebForm_FireDefaultButtondisplayed by ASP.NET.

+2
source

DefaultButton LinkButton. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.panel.defaultbutton.aspx

- style="display:none", , LinkButton.

+13

, wow: -)

asp.net:

<asp:Panel runat="server" DefaultButton="lbHello">
    First name: <asp:TextBox runat="server" ID="txtFirstName" />
    <asp:LinkButton ID="lbHello" Cssclass="button" runat="server" Text="Click me" OnClick="lbHello_Click" />
</asp:Panel>

JS:

$(document).ready(function () { $('.button').eventClick(); });

$.fn.eventClick = function() {
    function eventClick(a) { 
            if (a && typeof (a.click) == 'undefined') {
                a.click = function () {
                    var result = true;
                    if (a.onclick) result = a.onclick();
                    if (typeof (result) == 'undefined' || result) {
                        eval(a.getAttribute('href'));
                    }
                }
            }
        }
        return eventClick($(this).get(0));
}
+1

only work the first time we press enter in the text box. After adding text to the text field and then pressing the key, the button does not start by default.

0
source

I think this is very simple, just add the onkeypress js event of the text box where feedback is required.

txtUserName.Attributes.Add("onKeyPress", "javascript:if (event.keyCode == 13)
 __doPostBack('" + btnLogin.UniqueID + "','')");

Hope this will be helpful.

0
source

Source: https://habr.com/ru/post/1709588/


All Articles