ASP.NET HtmlAnchor Control

Definition and Usage

The HtmlAnchor control is used to control the <a> element.

In HTML, the <a> element is used to create hyperlinks. Hyperlinks can link to bookmarks or other pages.

Properties

Properties Description
Attributes Returns all attribute names and value pairs of the element.
Disabled Boolean value indicating whether the control is disabled. The default is false.
HRef The URL of the link.
id The unique id of the control.
InnerHtml

Sets or returns the content between the start and end tags of the HTML element.

Special characters are not automatically converted to HTML entities.

InnerText

Sets or returns all text between the start and end tags of the HTML element.

Special characters are automatically converted to HTML entities.

Name The name of the anchor.
OnServerClick The name of the function executed when the link is clicked.
runat Specifies that the control is a server control. It must be set to "server".
Style Sets or returns the CSS properties applied to the control.
TagName Returns the tag name of the element.
Target The target window to be opened.
Title The title displayed by the browser (e.g., the alt attribute of the img element).
Visible Boolean value indicating whether the control is visible.

Example

HTMLAnchor
In this example, we declared two HtmlAnchor controls in the .aspx file (remember to nest this control within the HtmlForm control). Then we modify the URL, target, and title of this HtmlAnchor control in the event handler. The Page_Load event is one of the many events understood by ASP.NET.