简体   繁体   中英

ASP.NET LinkButton when javascript is disabled

By definition LinkButton seems to invoke a javascript function which causes the script to freeze if I have disabled javascript. In such case the Button_Click event isn't even triggered.

Is there a quick and simple way to ignore the javascript generated for my LinkButton ? I want the Button_Click event to execute when my button is click with js disabled.

LinkButton generates an <a> so it cannot post without js. Making LinkButton work without js creates an unnecessary massive workaround.

A better solution is to style Button as a link. This was tested on Chrome, FF, IE8+, Edge:

    input[type="submit"], input[type="submit"]:focus, input[type="submit"]:active {
        /* Remove all decorations to look like normal text */
        background: none;
        border: none;
        display: inline;
        font: inherit;
        margin: 0;
        padding: 0;
        outline: none;
        outline-offset: 0;
        /* Additional styles to look like a link */
        color: blue;
        cursor: pointer;
        text-decoration: underline;
    }

    /* Remove extra space inside buttons in Firefox */
    input[type="submit"]::-moz-focus-inner {
        border: none;
        padding: 0;
    }

    // Markup
    <asp:Button runat="server" ID="btnTest" Text="Click" OnClick="btnTest_Click" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM