How do I use an asp:Button
or asp:LinkButton
as asp:Hyperlink
?
The existing Hyperlink just goes to another section on the same page: NavigateUrl="#Section2"
I want to do this in the aspx file without additional coding. Thanks.
The purpose is to have a button look instead of the underlined text BUT I don't want to use an image with hyperlink to achieve this purpose.
There is a middle way. If you want a HTML control but you need to access it server side you can simply add the
runat="server"
attribute:You can then alter the
href
server side usingAttributes
resulting in:
The best way to accomplish this is by simply adding "href" to the link button like below.
Using javascript, or doing this programmatically in the page_load, will work as well but is not the best way to go about doing this.
You will get this result:
You can also get the same results by using using a regular
<a href="" class=""></a>
.This can be done very easily using a PostBackUrl and a regular button.
You can use OnClientClick event to call a JavaScript function:
JavaScript code:
But i think the best would be to style a hyperlink with css.
Example :