Partager via


HyperLink Web Server Control Declarative Syntax 

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

<asp:HyperLink
    AccessKey="string"
    BackColor="color name|#dddddd"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    CssClass="string"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
        Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    Height="size"
    ID="string"
    ImageUrl="uri"
    NavigateUrl="uri"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    runat="server"
    SkinID="string"
    Style="string"
    TabIndex="integer"
    Target="string|_blank|_parent|_search|_self|_top"
    Text="string"
    ToolTip="string"
    Visible="True|False"
    Width="size"
/>

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

NoteNote

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

Example

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

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


   <h3>HyperLink Example</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"/>       
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>HyperLink Example</title>
</head>
<body>
<form id="Form1" runat="server">

   <h3>HyperLink Example</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"/>       
</form>
</body>
</html>
<%@ Page Language="JScript" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>HyperLink Example</title>
</head>
<body>
<form id="Form1" runat="server">

  <h3>HyperLink Example</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"/>       
</form>
</body>
</html>

See Also

Reference

HyperLink

Other Resources

Web Server Control Syntax