This topic has not yet been rated - Rate this topic

ReturnLink Class

Represents a link to either the site homepage, the site collection homepage, or the server root. The default location returned is the first valid location from the list. Generally the first valid location is the site homepage.

System.Object
  System.Web.UI.Control
    Microsoft.SharePoint.WebControls.SPControl
      Microsoft.SharePoint.WebControls.ReturnLink

Namespace:  Microsoft.SharePoint.WebControls
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class ReturnLink : SPControl
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
ReturnLink
Description

The Microsoft.SharePoint.WebControls.ReturnLink class inherits from Microsoft.SharePoint.WebControls.SPControl (a base server control) allowing you to build a hyperlink control linked to the current SPWeb URL, formatted with your description text. 

First the control gets a SPWeb from the current request context. After, it inspects whether the SPWeb.Url property of the returned SPWeb is available, which should always be the case. If for some reason this call errors out, the returned URL will be set to a “/” literal. The ReturnLink.Text property provides access to format the hyperlink description, while the hyperlink ID is set to the current instance ClientID. When building the return hyperlink statement the value encoding is preserved by using SPHttpUtility.HtmlUrlAttributeEncode() for the URL value and SPHttpUtility.NoEncode() for the ReturnLink.ClientID and ReturnLink.Text.

It should be noted that often times it is helpful to use the SharePoint text used in .NET resource files. When using the ReturnLink control, fields such as Resources:wss,multipages_back_to_site can help to sustain conformity and permit localization.

Usage Scenario

You typically use the ReturnLink control when building navigational components. A common use is when constructing custom breadcrumbs and menu components.

The following code samples show how you might use the ReturnLink within a WebPart:

C# Code Example 

protected override void CreateChildControls()
{
ReturnLink link = new ReturnLink();
link.Text = "Return To Home";
Controls.Add(link);
base.CreateChildControls();
}

Visual Basic .NET Code Example

Protected Overloads Overrides Sub CreateChildControls()
Dim link As New ReturnLink()
link.Text = "Return To Home"
Controls.Add(link)
MyBase.CreateChildControls()
End Sub 

Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com