Restoring the Navigate Up button with an AdditionalPageHead delegate control

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:

Restoring the Navigate Up button with an AdditionalPageHead delegate control

Getting ready

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.

How to do it...

Follow these steps to restore the navigate up button with a delegate control:

  1. Open the project created in the Creating a Visual Studio solution for custom delegate controls recipe of this chapter in Visual Studio.
  2. Add a new class to our Controls folder.
  3. Set the access modifier of our new class to public and inherit from the UserControl base class:
    public class RestoreBreadcrumb : UserControl
  4. Override the CreateChildControls method and add a monitored scope as follows:
    protected override void CreateChildControls()
    {
      using (new SPMonitoredScope("Code6587EN.Ch07.Controls.
      RestoreBreadcrumb::CreateChildControls"))
      {
      }
    }
  5. Get the master page from the current page:
    var masterPage = this.Page.Master;
  6. Get the AjaxDelta control that contains the breadcrumb control:
    var delta = masterPage.FindControl("DeltaBreadcrumbDropdown") as AjaxDelta;
  7. Ensure the AjaxDelta control is not null:
    if (delta != null)
  8. Get the breadcrumb control from the AjaxDelta control:
    var breadcrumb = delta.FindControl("GlobalBreadCrumbNavPopout") as PopoutMenu;
  9. Ensure the breadcrumb control is not null:
    if (breadcrumb != null)
  10. Set the 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";
  11. Add a STYLE element to set the display style of the breadcrumb container to inline-block.
  12. Add a new Empty Element item.
  13. In the 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>
  14. Add a new safe control entry to the new element with the following details:
    • (Name): RestoreBreadcrumb (the name of the class for our custom control)
    • Assembly: $SharePoint.Project.AssemblyFullName$
    • Namespace: Code6587EN.Ch07.Controls (the full namespace for the class, without the name of the class itself)
    • Safe: True
    • Safe Against Script: True
    • Type Name: RestoreBreadcrumb (the name of the class)
  15. Open the feature created previously. Ensure that the new element is included in the feature.
  16. Click on Start from the toolbar to deploy the solution and attach the debugger.
  17. Once the SharePoint site is loaded in the web browser (after clicking on Start), observe the restored breadcrumb control.

How it works...

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.156.251