![]() ![]() | ||
You can create hyperlinks in Web forms with hyperlink controls. You can see hyperlinks at work in Figure 17.6 in the HyperLinks example on the CD-ROM-to see how to set the various properties of hyperlinks, see the In Depth section of this chapter.
In the HyperLinks example on the CD-ROM, the two most important properties of the hyperlinks in the application, HyperLink1 and HyperLink2, are the Text and NavigateUrl properties. You set the Text property to the text you want the hyperlink to display at run time, and the NavigateUrl property to the URL you want the browser to navigate to when the hyperlink is clicked.
To assign a value to the NavigateUrl property at design time, click that property in the Properties window, opening the Select URL dialog you see in Figure 17.10. As you see in that dialog, you can select the URL type, which can be Absolute or Relative. You use Absolute if you want to specify an entire URL, and Relative if you want to specify an URL with respect to the current page (which you usually do if the URL is for another page in the same project). In this example, I'm creating hyperlinks both to the Visual Basic technical page at Microsoft (using an absolute URL: http://msdn.microsoft.com/vbasic/technical/articles.asp) and to another Web form in the same project (using a relative URL: WebForm2.aspx).
Tip |
Note that there are other properties you might want to set when working with hyperlinks, such as the Target property of the hyperlink, as well as the link, alink, and vlink properties of the Web form. See "Setting Hyperlink Colors" in Chapter 14. |
Now when the user clicks the "VB.NET Tech Info" link, for example, the browser will navigate to the Visual Basic technical page, as you see in Figure 17.11. (Note that in this case, I've set the hyperlink's Target property to _self, which means that the linked-to page replaces the current page when the user clicks the hyperlink.)
For reference, here is WebForm1.aspx for the HyperLinks example on the CD-ROM (this example needs no Visual Basic code):
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="HyperLinks.WebForm1"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>HyperLinks example</title> <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0"> <meta name="CODE_LANGUAGE" content="Visual Basic 7.0"> <meta name=vs_defaultClientScript content="JavaScript"> <meta name=vs_targetSchema content= "http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:HyperLink id=HyperLink1 style="Z-INDEX: 101; LEFT: 196px; POSITION: absolute; TOP: 80px" runat="server" Target="_self" NavigateUrl="http://msdn.microsoft.com/vbasic/technical/articles.asp"> VB.NET Tech Info</asp:HyperLink> <asp:Label id=Label2 style="Z-INDEX: 104; LEFT: 101px; POSITION: absolute; TOP: 121px" runat="server">Relative URL:</asp:Label> <asp:HyperLink id=HyperLink2 style="Z-INDEX: 103; LEFT: 198px; POSITION: absolute; TOP: 122px" runat="server" Target="_blank" NavigateUrl="WebForm2.aspx">Web Form 2</asp:HyperLink> <asp:Label id=Label1 style="Z-INDEX: 102; LEFT: 98px; POSITION: absolute; TOP: 80px" runat="server">Absolute URL:</asp:Label> </form> </body> </HTML>
![]() ![]() | ||