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.
Note |
---|
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. |
Hyperlinks
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.
To insert a hyperlink
In Design view, open your Web page for editing.
Select the text or image to use as a hyperlink.
On the Format menu, click Convert to Hyperlink. To use the keyboard in Design view, press Ctrl+L.
The Hyperlink dialog box appears.
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.
To set the target window of a hyperlink
Select the hyperlink.
In the Properties window, in the target box, use the down arrow to select a value.
Note 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">).
Note |
---|
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
In Design view, place the cursor on the page at the location that you want to bookmark.
On the Format menu, click Insert Bookmark. To use the keyboard in Design view, press Ctrl+Shift+L.
The Bookmark dialog box appears.
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">).
To insert a hyperlink to a bookmark
Select the text or image for the user to use as a hyperlink.
On the Format menu, click Convert to Hyperlink. To use the keyboard, press CTRL+L.
The Hyperlink dialog box appears.
In the Type list, select (other).
In the URL box, type a pound sign (#) and the bookmark name (for example, #bookmark), and then click OK.