Custom Navigation Menu Widget in Sitefinity 4

Using the default widget for a Sitefinity menu is great – when you don’t mind looking at all kinds of extra code elements thrown in. Keeping a menu simple is a great thing, helps with rendering, and decreases the amount of jQuery and JavaScript that gets loaded with the default widgets. This custom navigation control also takes in to account the “Show in Navigation” checks that can be set within Sitefinity.

Using the standard asp.Net SiteMap attributes, we can very easily add a custom widget that will pull in any page that is set to be shown in the navigation by the Sitefinity backend. Follow the code below to create your user control, and follow the steps below the code on adding a widget to the Sitefinity toolboxcontrols.

(Double click to enable plain-text copying)

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MainNav.ascx.cs" Inherits="Custom_Widgets_MainNav" %>
<asp:SiteMapDataSource ID="TopNavStart" runat="server" ShowStartingNode="false" />

<asp:Repeater runat="server" ID="LeftNav" DataSourceID="TopNavStart" OnItemDataBound="FirstLevel_ItemDataBound">

        <li class="links">
            <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Url") %>' Text='<%# Eval("Title") %>'></asp:HyperLink>


Now, there’s a few items that we are necessary to check for with Sitefinity 4’s Sitemap, and “Show In Navigation” checkboxes on individual pages. To check for pages that should not be shown in the navigation, modify the code-behind (MainNav.ascx.cs file) with these checks.

(Double click to enable plaint-text copying)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using Telerik.Sitefinity.Web;

public partial class Custom_Widgets_MainNav : System.Web.UI.UserControl
    int Count = 0;
    protected void Page_Load(object sender, EventArgs e)


    protected void FirstLevel_ItemDataBound(object sender, RepeaterItemEventArgs e)
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            //Check for "Show In Navigation" in Sitefinity SiteMap
            var data = e.Item.DataItem as PageSiteNode;
            if (data != null)
                if (data.ShowInNavigation == false)
                    e.Item.Visible = false;

Now that you have control, head over to my other post on adding custom control to Sitefinity Toolbox

Posted in, C-Sharp, C#, HTML, Sitefinity 4