HyperLink vs LinkButton

What Is the Difference Between Asp:HyperLink &
Asp:LinkButton

Asp:HyperLink

Navigation

This Can use for navigation.

Eg :- <asp:HyperLink ID=”HyperLink1″
runat=”server”
NavigateUrl=”~/Default.aspx” >Home</asp:HyperLink>

PostBack

The HyperLink will not PostBack your page to the server. It
will post a simple request to the server for the URL you set as NavigateUrl.

OnClick event

The HyperLink doesn’t have
the OnClick event.

Asp:LinkButton

Navigation

It also use for navigation.

Eg:- <asp:LinkButton ID=”LinkButton1″
runat=”server”
PostBackUrl=”~/Default.aspx”> Save </asp:LinkButton>

PostBack

The LinkButton works exactly as a normal Button but it looks like a HyperLink (<a
href=”…”> something </a>)
, so it will PostBack your page to
the server allowing you to do your business (like setting variables at
session level or doing some DB operation or whatever).

OnClick event

We can Use OnClick event.

So, if you’re asking yourself “which one should I use?

Here’s the answer: if you need to do any operation with data
that’s on the page you will have to use a LinkButton (or a Button), but if you
just need to redirect the user to somewhere else go for a HyperLink (You will
avoid half roundtrip!).

E.g.
you want to avoid having Button
or LinkButton handlers with
just this code: Response.Redirect(“Default.aspx”);

And key
thing about SEO Friendly it is better to use HyperLink.

Leave a Reply