The out-of-the-box master pages from SharePoint 2010 included a breadcrumb control that would allow a user to easily navigate up the current site hierarchy. The out-of-the-box master pages in SharePoint 2013 have hidden this control. We previously accomplished this in a master page in Chapter 3, Branding SharePoint with Custom Master Pages and Page Layouts. In this recipe, however, we will accomplish this with an AdditionalPageHead
delegate control. This allows us to restore the button regardless of which master page is being used. The following screenshot illustrates the restored breadcrumb control:
We should have already created our Visual Studio project with the help of the Creating a Visual Studio solution for custom delegate controls recipe of this chapter before starting this recipe.
Follow these steps to restore the navigate up button with a delegate control:
Controls
folder.public
and inherit from the UserControl
base class:public class RestoreBreadcrumb : UserControl
CreateChildControls
method and add a monitored scope as follows:protected override void CreateChildControls() { using (new SPMonitoredScope("Code6587EN.Ch07.Controls. RestoreBreadcrumb::CreateChildControls")) { } }
var masterPage = this.Page.Master;
AjaxDelta
control that contains the breadcrumb control:var delta = masterPage.FindControl("DeltaBreadcrumbDropdown") as AjaxDelta;
AjaxDelta
control is not null:if (delta != null)
AjaxDelta
control:var breadcrumb = delta.FindControl("GlobalBreadCrumbNavPopout") as PopoutMenu;
breadcrumb
control is not null:if (breadcrumb != null)
breadcrumb
control to be visible, set the ThemeKey
property, and set the IconUrl
property using the following code:breadcrumb.Visible = true; breadcrumb.ThemeKey = "spcommon"; breadcrumb.IconUrl = "/_layouts/15/images/spcommon.png";
STYLE
element to set the display style of the breadcrumb
container to inline-block
.Elements.xml
file of the new element, register our control with the AdditionalPageHead
delegate control using the following code:<?xml version="1.0" encoding="utf-8"?> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Control Id="AdditionalPageHead" Sequence="11" ControlClass="Code6587EN.Ch07.Controls.RestoreBreadcrumb" ControlAssembly="$SharePoint.Project.AssemblyFullName$"></Control> </Elements>
RestoreBreadcrumb
(the name of the class for our custom control)$SharePoint.Project.AssemblyFullName$
Code6587EN.Ch07.Controls
(the full namespace for the class, without the name of the class itself)True
True
RestoreBreadcrumb
(the name of the class)breadcrumb
control.The out-of-the-box master pages included with SharePoint 2013 already include the required controls on the page to render the breadcrumb control. However, they are hidden. In our AdditionalPageHead
delegate control, we are locating the control, instructing it to display, and configuring the icon to be correctly inherited from the currently applied SharePoint theme.
3.133.156.251