Search code examples
javascriptasp.netlinkbutton

ASP.NET: asp:LinkButton with Javascript disabled?


i want to use an asp:LinkButton, since it looks like a link, yet also has server-side Click handler.

But the web-server seems unable to detect if javascript is disabled on the client, and doesn't render into a mechanism that still works.

Is it possible to have a link that looks like a link, but has server-side OnClick event handler?


Answer

The answer is no, but below are some workaround ideas. Accepted the one with non-zero up-votes.


Solution

  • You could use CSS to style a button to look like a link, but this will be very much browser dependant, depending on the CSS implementation.


    Edit: I feel compelled to complete my answer since it's been accepted.

    An asp:LinkButton renders to an HTML link, and as such cannot post to a web page; but can only make get requests. To work around this MS use JavaScript to action the post. This is not possible however if Javascript is disabled.

    asp:Button and asp:ImageButton are different. They submit the HTML form by posting to a web page (or get depending on the form attributes) by using true HTML form elements. So these will work without JS intervention.

    Some browsers will allow CSS styling to style a button to look like a link, and as such this can be used to work around the issue.