Share via


HyperLink Web Server Control

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

<asp:HyperLink id="HyperLink1"
     NavigateURL="url"
     Text="HyperLinkText"
     ImageUrl="url"
     Target="window"
     runat="server"/>
or
<asp:HyperLink id="HyperLink1"""
     NavigateURL="url"
     ImageUrl="url"
     Target="window"
     runat="server">

   Text

</asp:HyperLink>

Remarks

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 simply place the text between the opening and closing tags of the HyperLink control. To display an image, set the ImageUrl property.

Note   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:

_blank Displays the linked page in a new window without frames.
_parent Displays the linked page in the immediate frameset parent.
_self Displays the linked page in the frame with focus.
_top Displays the linked page in a the full window without frames.

CAUTION   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.

Example

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

<html>
<head>
</head>
<body>

   <h3>HyperLink Sample</h3>
   Click on the HyperLink:<br>  
   <asp:HyperLink id="hyperLink1"
        ImageUrl="images\pict.jpg"
        NavigateURL="https://www.microsoft.com"
        Text="Microsoft Official Site"
        Target="_new"
        runat="server"/>      

</body>
</html>

See Also

Web Server Controls | HyperLink Class