How to: Insert HTML Hyperlinks and Bookmarks in Design View for Web Forms Pages

Hyperlinks and bookmarks are important tools for helping users to navigate quickly within and across web pages to the content that they need.

NoteNote

The techniques described in this page apply only to ASP.NET Web Forms pages. They do not apply to pages that you create using ASP.NET MVC (Model View Controller) or ASP.NET Web Pages.

When clicked, a hyperlink attempts to find an HTML document and open it in the web browser. It locates this new document by using a Uniform Resource Locator (URL) string. For example, the hyperlink <A HREF="mypage.htm"> looks in the current folder for a page named Mypage.htm and then displays this page in the current frame.

  1. In Design view, open your Web page for editing.

  2. Select the text or image to use as a hyperlink.

  3. On the Format menu, click Convert to Hyperlink. To use the keyboard in Design view, press Ctrl+L.

    The Hyperlink dialog box appears.

  4. In the URL box, type the path to the resource or click the Browse button. Navigate to the target page or file, and then click OK.

Setting the Target Attribute

You can use target attribute to specify how the hyperlink opens in the browser by specifying values for it like _blank, _parent, or _top. Setting the target value to _blank opens the link in a new browser window, or in a new browser tab in a tabbed browser. If the target attribute is not set, the hyperlink displays the target page in the current browser window.

  1. Select the hyperlink.

  2. In the Properties window, in the target box, use the down arrow to select a value.

    NoteNote

    The DOCTYPE of the web page must be HTML 4 or HTML 5 for the target attribute to appear in the Properties window. The target attribute on anchor elements is not allowed in the XHTML 1.1 document type definition.

Bookmarks

A bookmark creates a location within an HTML document to which a hyperlink can jump (for example, <a name="anchor">).

NoteNote

In HTML5, the <a> tag does not have a name attribute. You can use the id attribute instead to create a bookmark, as in the following example. This syntax also works in HTML 4 in most browsers.

<p id="NewBookmark">Bookmark location</p>

To insert a bookmark

  1. In Design view, place the cursor on the page at the location that you want to bookmark.

  2. On the Format menu, click Insert Bookmark. To use the keyboard in Design view, press Ctrl+Shift+L.

    The Bookmark dialog box appears.

  3. Type a name for the bookmark, and then click OK.

You can create a hyperlink that scrolls the current HTML page to a location that already has a bookmark. The link to the bookmark uses an abbreviated URL (for example, <a href="#bookmark">).

  1. Select the text or image for the user to use as a hyperlink.

  2. On the Format menu, click Convert to Hyperlink. To use the keyboard, press CTRL+L.

    The Hyperlink dialog box appears.

  3. In the Type list, select (other).

  4. In the URL box, type a pound sign (#) and the bookmark name (for example, #bookmark), and then click OK.

See Also

Reference

Hyperlink Dialog Box

Other Resources

XHTML Standards in Visual Studio and ASP.NET