views:

2477

answers:

4

i want to use an asp:LinkButton, since it looks like a link, but 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.

+4  A: 

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, however if JS is disabled this is not possible.

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.

Ady
A more complete version would have some sample code - otherwise it just begs another SO question called "How do i use CSS and Javascript" to create a button that looks like a link.
Ian Boyd
A: 

Just an idea:

Render an input button and use javascript to change it into a link. The button would work for non-javascript enabled browser and become a link for those who have javascript.

Cristian Libardo
A: 

There is no INPUT type which will look like a link. If you want to use a link to perform an INPUT type activity on a web page, it will have to navigate to the same page that you are on.

You can pass a query string variable with the link, and respond to that. It won't act exactly like a postback, instead it will just navigate to the same page that you are on.

Matt Brunell
+1  A: 

With anything like this in ASP.Net I'd usually render the control, along with an "accessible control" that's hidden with JavaScript. So in this case it would render a LinkButton (hidden by default via styles), and a normal button, with some javascript registered to hide the Button and show the LinkButton.

It's quite a common workaround for ASP.Net control that don't play nicely without javascript, or when you need "Autopostback" without Javascript.

Steven Robbins
Some sample code to explain what you're talking about would be good.
Ian Boyd