Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use asp:HyperLink

Tags:

html

.net

asp.net

In what circumstances is it recommended to use the asp:HyperLink control?

I've come from a HTML background and am creating sites with ASP.NET and I tend to use raw HTML by default, whereas my colleagues use the asp: control versions.

In some cases that makes sense for the extra intellisense e.g. when creating <label>, but for asp:Hyperlink, it seems more straightforward to enter the anchor tag directly.

like image 321
Durathor Avatar asked May 11 '11 11:05

Durathor


1 Answers

The key benefit is that the Hyperlink is a control that can be programatically manipulated in the code-behind.

ASPX

<asp:HyperLink ID="hlLink" runat="server" />

ASPX.CS

hlLink.NavigateUrl = string.Format("~/SomeFolder/SomePage.aspx?SomeKey={0}", someKey);
like image 193
James McCormack Avatar answered Oct 17 '22 05:10

James McCormack