Where & When to use asp:Hyperlink Control?

Hyperlink control is used to jump to another location or to execute the script code. When rendered on the page, it implements an anchor <a/> tag.

Its properties like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. are implemented through style properites of <a/> HTML tag. You can set its Text either by setting Text property in the .aspx page or from server side page. (other properties can also be set from both pages)

Following are some important properties that are useful.

NavigateUrl Used to specify the location to jump to.
ImageUrl Used to place an image instead of text as Hyperlink.

If you need to fire any client side function (JavaScript) after clicking this, you need to prefix its NavigateUrl property with JavaScirpt like this. NavigateUrl=”javascript:MyFunction()”

As this control is the server side form of HTML anchor tag so it is preferred to not use it and use simply anchor tag (<a />), however there are certain scenario where you need to decide the navigational url or text for the link through server side dynamically, in that scenario you can use it.

Tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *