JavaScript Editor Javascript validator     Javascripts

Main Page


Previous Section Next Section

5.5 HyperLink Control

A 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:

ImageUrl

The path to an image (rather than text) to display. If this attribute is used, the control appears to the user as identical to an ImageButton control, although the ImageButton control still posts the form and the HyperLink control only navigates.

NavigateUrl

The target URL to navigate to.

Text

The text string that will be displayed on the browser as the link. If both the Text and ImageUrl properties are set, the ImageUrl takes precedence. The text is displayed if the image is unavailable.

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.

Target

Defines the target window or frame that will load the linked page. The value is case insensitive and must begin with a character in the range of a to z, except for the special values shown in Table 5-3, all of which begin with an underscore.

Table 5-3. Special values of the Target attribute

Value

Description

_blank

Renders the content in a new unnamed window without frames.

_new

Not documented, but behaves the same as _blank.

_parent

Renders the content in the parent window or frameset of the window or frame with the hyperlink. If the child container is a window or top-level frame, it behaves the same as _self.

_self

Renders the content in the current frame or window with focus. This is the default value.

_top

Renders the content in the current full window without frames.

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 control
figs/pan2_0504.gif

The 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.

    Previous Section Next Section


    JavaScript Editor Javascript validator     Javascripts 
    Bitcoin Gambling Site



    ©