asp.net.ph

Skip Navigation Links

Adding HyperLink Controls to a Web Forms Page

Controls You Can Use on Web Forms   ASP.NET Standard Controls   HyperLink Control


HyperLink controls can render as text or as graphics.

To add a HyperLink control to a Web Forms page

  1. Declare an <asp:HyperLink> element on the page. For syntax, see Hyperlink Control Syntax.
  2. Specify the format of the link in the page by doing one of the following:
    • To create a text link, set the control’s Text property. You can include HTML formatting in the property; for example, you can bold an individual word in the text by placing a <B> element around it in the Text property.
    • To create a graphical link, set the control’s ImageUrl property to the URL of a .gif, .jpg, or other Web graphic file.

      NOTE: If you set both the ImageUrl and Text properties, the ImageUrl property takes precedence.

  3. Set the NavigateUrl property to the URL of the page to link to.
  4. Optionally, set the ID of a target window or frame to display the linked page in. You can either specify a window by name or you can use predefined target values such as _top, _parent, and so on.

    TIP: You can change the appearance of the link text — for example, whether it is underlined — using styles.

The following shows how you can set the Hyperlink control’s link text and destination page at run time.

void Page_Load ( object src, EventArgs e ) {
   Hyperlink1.Text = "Home";
   Hyperlink1.NavigateURL = "/asp.net.ph";
}
  C# VB
HyperLink1.aspx
Run Sample | View Source

Whilst the sample simply shows how the Text and NavigateUrl properties can be set as the page loads, you can extend this functionality by getting the values of these properties from user input, or passed from some other event-handling method.

See Also

Introduction to the HyperLink Control   Web Forms Data Binding



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note