5.5 HyperLink ControlA HyperLink control looks similar to a LinkButton control. However, there is a fundamental difference: the HyperLink control only navigates to the target URL, while the LinkButton control posts the form and, if the event handler chooses, navigates to the target URL. The HyperLink control has four specific attributes:
If the browser supports tool tips and the ToolTip property has not been set, then the Text value will display as a tool tip. If the ToolTip property has been set, then the ToolTip text string will display as a tool tip.
Example 5-8 and Example 5-9 demonstrate a hyperlink in C# and VB.NET, respectively. Example 5-8. HyperLink in C#, csASPHyperLink.aspx<%@ Page Language="C#" %> <html> <body> <form runat="server"> <h1>ASP Controls</h1> <h2>HyperLink</h2> <asp:hyperLink id="hypLink" NavigateUrl="//localhost/progaspnet/TargetPage.aspx" Text="HyperLink to Target Page" target="_self" Font-Name="Impact" Font-Size="16pt" toolTip="Click here to go to Target Page." runat="server" /> </form> </body> </html> Example 5-9. HyperLink in VB.NET, vbASPHyperLink.aspx<%@ Page Language="VB" %> <html> <body> <form runat="server"> <h1>ASP Controls</h1> <h2>HyperLink</h2> <asp:hyperLink id="hypLink" NavigateUrl="//localhost/progaspnet/TargetPage.aspx" Text="HyperLink to Target Page" target="_self" Font-Name="Impact" Font-Size="16pt" toolTip="Click here to go to Target Page." runat="server" /> </form> </body> </html> The result of running Example 5-8 or Example 5-9 is shown in Figure 5-4. Figure 5-4. HyperLink controlThe HyperLink control is rendered on the client browser as an HTML anchor tag (that is, <a>). You can verify this by examining the source code for the web page on your browser. |