Halle
Halle

Reputation: 77

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.

Upvotes: 0

Views: 77

Answers (1)

Jaqen H'ghar
Jaqen H'ghar

Reputation: 16824

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" />

Upvotes: 1

Related Questions