HyperLink Web Server Control Declarative Syntax

Creates a link on the page that users can click to move to another page.

    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    ForeColor="color name|#dddddd"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"

Use the HyperLink control to create a link that moves you to another page or location on the page. Specify the page or location to link to by using the NavigateUrl property. The link can either be displayed as text or an image. To display text, either set the Text property or place the text between the opening and closing tags of the HyperLink control. To display an image, set the ImageUrl property.


Because the <asp:HyperLink> element does not need to contain content, you can close the tag with /> instead of using a separate closing tag.

If both the Text and ImageUrl properties are set, the ImageUrl property takes precedence. If the image is unavailable, the text in the Text property is then displayed. On browsers that support the ToolTips feature, the value of the Text property is displayed when the mouse pointer is placed over the HyperLink control.

You can specify the frame or window to display the linked page by setting the Target property. Values must begin with a letter in the range of a through z (case insensitive), except for the following special values, which begin with an underscore:


Displays the linked page in a new window without frames.


Displays the linked page in the immediate frameset parent.


Displays the linked page in the frame with focus.


Displays the linked page in the full window without frames.

Caution noteCaution

Text is not HTML encoded before it is displayed in the HyperLink control. This makes it possible to embed script within HTML tags in the text. If the values for the control come from user input, be sure to validate the values to help prevent security vulnerabilities.

For detailed information on the HyperLink Web server control's properties and events, see the HyperLink documentation.

When using the HyperLink Web server control to navigate between pages in your application, you can use the tilde ("~") wildcard to signify the root of your application without the need to hardcode a directory name into the application relative URL. For example, you could use "~/Default.aspx" to navigate back to the Default.aspx page for your application from any page in any subdirectory in the application.

The following example demonstrates how to use a HyperLink control to move to another Web page.

<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" >
    <title>HyperLink Example</title>
<form id="Form1" runat="server">

   <h3>HyperLink Example</h3>

   Click on the HyperLink:<br />  

   <asp:HyperLink id="hyperlink1" 
                  Text="Microsoft Official Site"

Community Additions