Mono Class Library: System.Web.UI.WebControls Namespace

System.Web.UI.WebControls.HyperLink Class

Represents a link of the html page and presents it in text representation or with an image. It takes care of the relative paths.

See Also: HyperLink Members

System.Object
     System.Web.UI.Control
          System.Web.UI.WebControls.WebControl
               System.Web.UI.WebControls.HyperLink

[System.ComponentModel.Designer("System.Web.UI.Design.WebControls.HyperLinkDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
[System.ComponentModel.DefaultProperty("Text")]
[System.Web.UI.ToolboxData("<{0}:HyperLink runat="server">HyperLink</{0}:HyperLink>")]
[System.Web.UI.ParseChildren(false)]
[System.Web.UI.DataBindingHandler("System.Web.UI.Design.HyperLinkDataBindingHandler, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.Web.UI.ControlBuilder(typeof(System.Web.UI.WebControls.HyperLinkControlBuilder))]
public class HyperLink : WebControl

Remarks

System.Web.UI.WebControls.HyperLink shows a link (yes, those that you know widely from the web). It resolves the relative path names and translate it to a relative path in terms of the root of the website.

Use it widely instead of plain html tags. One benefit is that you'll be able of managing the link programatically, and will be able to detect broken links. Of course, you'll have to program DetectBrokenLinks() first :-)

There could be some thoughts such as "why should I use it, since I could use a flat html?". Well, System.Web.UI.Controls.HyperLink provides some nice features, and especially one that many web developers were missing: The handling of relative and/or absolute path names. When I develop a website in my machine, I never use the root of the webserver, because it would left unusable for other projects. Rather, I use a subdirectory or a user path; thus, locally my website is something like http://localhost/mywebsite/ or http://localhost/~me/mywebsite/. Later I deploy it to the root of http://www.mywebsite.com, and here I have the problem: The path to aage in my machine is /mywebsite/images/goofy.jpg, but in the website, it becomes /images/goofy.jpg. Well, using an System.Web.UI.WebControls.HyperLink object I don't have to worry about it any more: I just set the hyper-reference to relative paths (images/goofy.jpg, goofy.jpg, ./images/goofy.jpg or ../../../images/goofy.jpg) and the ASP.NET engine will translate it to the correct representation.

Requirements

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0