user2261573
user2261573

Reputation: 551

ASP.NET Hyperlinks asp:HyperLink vs A href

In asp.net when should I use:

<asp:HyperLink   
ID="Home"   
runat="server"  
Text="Home"  
NavigateUrl="./Home.aspx">

and when shoudl I use

<a href="./UnsignedVsSignedTut.aspx">Home</a> 

?

Upvotes: 3

Views: 24597

Answers (3)

MikeM
MikeM

Reputation: 27415

1). If you just need a link on a page, use an HTML anchor element (<a href="...">...</a>).

2). If you need to dynamically control the link's properties (such as href, text, visibility, etc) use a server-side anchor/link control

Either a server-side "webcontrol" System.Web.UI.WebControls.HyperLink

<asp:HyperLink id="aExample" runat="server" NavigateUrl="..." .../>

or a server-side "htmlcontrol" System.Web.UI.HtmlControls.HtmlAnchor

<a id="aExample" runat="server" href="...">...</a>

3). Additionally, server-side controls have potential for more sophisticated programming, such as building the anchor element dynamically from a base System.Web.UI.Control

Upvotes: 1

Vitaliy Shibaev
Vitaliy Shibaev

Reputation: 1460

ASP.NET server controls give you more abilities (e.g. event handling, more properties). HTML controls on the other hand are much simpler.

Both controls are fine. Usually you can start from HTML control and migrate to asp:HyperLink if need later.

You can also look at these discussions:

Upvotes: 3

YK1
YK1

Reputation: 7622

When you use asp:HyperLink you make it accessible from code behind. Which means like any other ASP.NET controls, you can modify it from code behind. asp:HyperLink can also be data bound.

In general case, when you have a static hyperlink I guess you can use both interchangeably.

Upvotes: 0

Related Questions