Custom Cross site collection Navigation using user control

Hi,

Sometimes the out of box navigation does not provides us the type of navigation wants on the whole application. To make such custom navigation which is consistent throughout many site collection it is batter to create a custom user control and simply register it in to the master page. Applying the same master page on every site collection will do the job.

Follow below steps to create the user control:

1) Right click on the project and the click on Add New Item.

2)Then add a User Control. Name it as per the convention.

3)Under the ascx file create any type of control you wana use, I prefer asp menu:

<div >
<asp:Menu ID="MyTopMenu" Orientation="Horizontal" runat="server">
<StaticMenuItemStyle CssClass="topNavStaticMenuItem"/>
<StaticSelectedStyle CssClass="topNavSelectedStaticMenuItem"></StaticSelectedStyle>
</asp:Menu></div>

4) Now next step is to populate the menu with the tabs:

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var homeLinkTitle = "Home";
var homeLinkUrl = "http://mohitvash.wordpress.com";

ApoteoseTopMenu.Items.Add(new MenuItem(homeLinkTitle) { NavigateUrl = homeLinkUrl, Selected = true });
ApoteoseTopMenu.Items.Add(new MenuItem("Google") { NavigateUrl = "www.google.com", Selected = false });
}
}

5) Now next step is to add this control to the master page:

<%@ Register TagPrefix="MyTopNavControl" TagName="CurrentPageControl" src="~/_ControlTemplates/MyTopNavControl.ascx" %>

also add below line at the required placeholder.

<MyTopNavControl:CurrentPageControl ID="topNav" runat="server"></MyTopNavControl:CurrentPageControl>

6) Build and deploy the application and enjoy the consistent navigation :)

Happy Sharepointing....

Comments

Popular posts from this blog

Hide Ribbon on SharePoint 2013 using CSS

Get Comment Count in SharePoint

Configure external site as content sources in sharepoint search