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> 

?

+4
source share
3 answers

ASP.NET server controls give you more options (like event processing, more properties). HTML controls, on the other hand, are much simpler.

Both controls are fine. You can usually start with HTML control and migrate to asp: HyperLink if needed later.

You can also look at these discussions:

+3
source

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

2). If you need to dynamically control link properties (e.g. href, text, visibility, etc.), use server side binding / linking

Or server "webcontrol" System.Web.UI.WebControls.HyperLink

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

or server "htmlcontrol" System.Web.UI.HtmlControls.HtmlAnchor

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

3). In addition, server controls have the potential for more complex programming, for example, dynamically building a binding element from the System.Web.UI.Control database

+1
source

When you use asp:HyperLink , you make it available from the code behind. This means that, like any other ASP.NET control, you can change it from code. asp:HyperLink can also be data bound.

In the general case, when you have a static hyperlink, I think you can use both options.

0
source

Source: https://habr.com/ru/post/1488809/


All Articles