开发者

Why use asp:HyperLink

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 a开发者_JAVA技巧sp:Hyperlink, it seems more straightforward to enter the anchor tag directly.


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);


Besides the hyperlink, a lot of other controls suport the runat=server tag which allows the control to be used from code behind. Makes life a lot simpler.

For example depending on an action that the user does, you can disable the hyperlink or change the navigateurl.

On the other hand, if you just want a static link, it is ok just to use an anchor tag

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜