Click here to Skip to main content
15,880,503 members
Articles / Productivity Apps and Services / Sharepoint
Tip/Trick

Create Custom Top Navigation Menu in Sharepoint 2013

Rate me:
Please Sign up or sign in to vote.
4.90/5 (3 votes)
1 Jul 2016CPOL1 min read 22.5K   228   3   3
This tip will teach you how to create custom top navigation menu using custom list and user controls in SharePoint 2013.

Introduction

Please follow the below steps to create a custom top navigation menu in Sharepoint 2013.

  1. Create a custom list.
  2. Create user controls to read all items in the list and create a menu structure XML.
  3. Create a delegate control to call the user control in the master page.
  4. Create a custom style sheet for the menu.

Create a Custom List

Follow the below steps to create a custom list:

  1. Navigate to Sharepoint site contents.
  2. Click "Add an App".
  3. Select custom list and click create.
  4. The list should contain columns which are mentioned in the screen shot.

Image 1

The lookup column refers to the same list "title" column.

Image 2

Create a User Control

Refer this link to create a user control - https://msdn.microsoft.com/en-us/library/ee231548(v=vs.110).aspx

C#
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using AHC.SP13.BICC.Webparts.Code;

namespace AHC.SP13.BICC.Webparts.ControlTemplates.AHC.SP13.BICC.Webparts
{
    public partial class TopNavigationMenu : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           if (!this.Page.IsPostBack)
            {
                MenuHelper mnu = new MenuHelper("Top Menu");
                ltMenu.Text = mnu.RendMenuItems();
            }
        }
    }
}

I have attached MenuHelper.cs file to the tip.

Create Delegate Control to Call the User Control in Master page

Follow the below link to create a delegate control:

XML
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Control Id="CustomMenu" Sequence="10" 
  ControlSrc="~/_controltemplates/15/AHC.SP13.BICC.Webparts/TopNavigationMenu.ascx" 
  xmlns="http://schemas.microsoft.com/sharepoint/" />
  <Control Id="LoggedInUserName" Sequence="10" 
  ControlSrc="~/_controltemplates/15/LoggedInUser.ascx" 
  xmlns="http://schemas.microsoft.com/sharepoint/" />
</Elements>

Call the Delegate Control in the Master Page

Add this line in the master page where you want to place the menu:

C#
<!--SPM:<SharePoint:DelegateControl runat="server" ControlId="CustomMenu "/>-->

Before adding the below line in the master page, please upload attached menu.css file in the style library:

XML
<!--SPM:<SharePoint:CssRegistration Name="&#60;
%$SPUrl:~SiteCollection/Style Library/Menu.css%&#62;" runat="server"/>-->

History

  • 1st July, 2016: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
India India
I am Senthil Gopal, a SharePoint Lead based out of Chennai, India.
I have around 9+ years of experience in Microsoft technologies such as C#,Asp.net, SharePoint 2010 and 2013.
This is a Social Group

4 members

Comments and Discussions

 
QuestionFirst picture Pin
Nelek1-Jul-16 1:34
protectorNelek1-Jul-16 1:34 
AnswerRe: First picture Pin
senthill1-Jul-16 1:46
professionalsenthill1-Jul-16 1:46 
GeneralRe: First picture Pin
Nelek4-Jul-16 20:55
protectorNelek4-Jul-16 20:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.