7

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.

5 Answers 5

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
2

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.

1 Comment

Great idea, progressive enhancement!
2

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.

1 Comment

Some sample code to explain what you're talking about would be good.
0

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.

Comments

0

Just for the record, what you're asking for is possible.

You have to to configure the control like this:

<asp:LinkButton ID="lbtnRequestReview" Text="[ Request Plan Review ]" OnCommand="lbtnRequestReview_Command" CommandName="cmd" CommandArgument="0" CausesValidation="false" runat="server"/>

and put this in the code-behind:

protected void lbtnRequestReview_Command(Object sender, CommandEventArgs e)
        {
           //...
        }

You can find more detailed information here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.