Click here to Skip to main content
Click here to Skip to main content

Navigation Custom Control (SharePoint Server 2010)

By , 15 May 2010
 

Introduction

For use in Microsoft SharePoint Server 2010, this web control is an alternative to the out-of-the-box "Current Navigation" a.k.a. AspMenu. It renders navigational nodes using HTML list tags, like:

This web control is adapted from my SharePoint Server 2007 version for use in SharePoint Server 2010.

Description

The web control uses PortalSiteMapProvider to render navigation nodes. Although the SharePoint 2010 version of AspMenu supports emission of HTML list tags with the use of property UseSimpleRendering, it is still fairly rigid in how children levels are displayed when you are at the top level and when you navigate down the nodes.

It has several public properties:

  • SiteMapProvider - A site map provider of type PortalSiteMapProvider. Default is CurrentNavigation.
  • StartNodeKey - Server relative URL for a starting sub-site. For example: /PressReleases/2010. Default is the root site.
  • IncludeSubSites - Include sub-sites? Allowed values are True, False, or PerWeb. Default is PerWeb, i.e., a per sub-site setting, configurable in Site Actions > Navigation (Look and Feel).
  • IncludePages - Include pages? Allowed values are True, False, or PerWeb. Default is PerWeb, i.e., a per sub-site setting, configurable in Site Actions > Navigation (Look and Feel)
  • IncludeHeadings - Include headings? Allowed values are True, False.
  • IncludeAuthoredLinks - Include authored links? Allowed values are True, False.
  • MaxLevels - Maximum number of node levels. Default is 0, i.e., no limit.
  • CompactMode - If set to True, the navigation expands the top level nodes and all parent nodes to the current node. In the example below, nodes Child1, Child2, and Child3 are the top level nodes:
        Child1
        Child2
            Child21
                Child211 (Current Node)
                    Child2111
        Child3

    If set to False, sibling nodes to the current node and its parent nodes will also be shown. For example:

        Child1
        Child2
            Child21
                Child211 (Current Node)
                    Child2111
                Child212
            Child22
            Child23
        Child3

    Default is False.

  • ListCssClass - CSS class name for the outermost <ul> tag.
  • NodeCssClass - CSS class name for regular hyperlinked nodes.
  • CurrentNodeCssClass - CSS class name for a selected node.
  • CurrentNodeParentCssClass - CSS class name for the lowest level node under which there is a selected node.
  • NoUrlNodeCssClass - CSS class name for nodes with no URL, like headings.

The control also uses a resource file to store all messages and property attribute UI strings. It demonstrates how to develop a custom class that inherits CategoryAttribute or DescriptionAttribute and returns a localized string from your own Resource Manager.

The sample Visual Studio 2010 solution includes all the support files you need to build and deploy this web control, minus the strong name key file (key.snk). It makes full use of the built-in SharePoint integration. No more third party tools or custom pre and post build scripts are needed to build the SharePoint solution file.

Notes

The web control does not fully support site hierarchy containing navigational "headings" because they cannot be clicked to open up child nodes. The navigation will, however, show parent headings if one of the child nodes is a current node.

Installation

Open SharePoint 2010 Management Shell, add solution file QuestechNavigation.wsp using Add-SPSolution like:

Add-SPSolution "C:\QuestechSystems.Navigation\bin\Release\QuestechNavigation.wsp"

Or using stsadm, add solution file QuestechNavigation.wsp like:

stsadm -o addsolution -filename 
	"C:\QuestechSystems.Navigation\bin\Release\QuestechNavigation.wsp"

Go to SharePoint 2010 Central Administration/System Settings/Manage farm solutions. Deploy the installed solution to selected web applications. To insert the web control to a publishing page, modify the appropriate master page or page layout as follows:

...
<%@ Register Tagprefix="QuestechPublishingWebControls"
    Namespace="QuestechSystems.SharePoint.Publishing.WebControls"
    Assembly="QuestechSystems.SharePoint.Publishing.Navigation, Version=1.0.0.0, 
              Culture=neutral, PublicKeyToken=57d955ce9c425b79" %>
...
...
<QuestechPublishingWebControls:Navigation CompactMode="False" runat="server" />
...

History

  • 15th May, 2010: Initial post

License

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

About the Author

Stephen Huen
Web Developer Questech Systems
Canada Canada
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionNeed Clean Code: No DivsmemberMember 860186627 Jan '12 - 12:02 
GeneralLevel 2 CSSmemberMember 814557329 Sep '11 - 12:19 
GeneralRe: Level 2 CSS [modified]memberMember 814557329 Sep '11 - 12:25 
QuestionStarting node offset?memberjomungand18 Nov '10 - 5:12 
QuestionRe: Starting node offset?memberMember 33236308 Aug '11 - 20:10 
GeneralTrying to set StartNodeKey programmatically...memberwoodsss23 Sep '10 - 2:57 
QuestionNavigation not visiblememberS0CAR03 Sep '10 - 3:14 
AnswerRe: Navigation not visiblememberStephen Huen3 Sep '10 - 10:11 
GeneralRe: Navigation not visiblememberS0CAR05 Sep '10 - 19:58 
No, I didn't, this was the reason, thank you. Smile | :)
GeneralI am new to SharePoint and this Code...I am having trouble adding this code to a master pagememberlarrydunn552 Sep '10 - 8:59 
GeneralRe: I am new to SharePoint and this Code...I am having trouble adding this code to a master pagememberStephen Huen3 Sep '10 - 10:12 
QuestionThe control type 'QuestechSystems.SharePoint.Publishing.WebControls.Navigation' is not allowed on this page. The type is not registered as safememberdatasmithtech13 Jul '10 - 14:39 
AnswerRe: The control type 'QuestechSystems.SharePoint.Publishing.WebControls.Navigation' is not allowed on this page. The type is not registered as safememberStephen Huen14 Jul '10 - 16:43 
QuestionThe project type is not supported by this installationmemberMember 44387929 Jul '10 - 3:46 
AnswerRe: The project type is not supported by this installationmemberStephen Huen9 Jul '10 - 7:50 
Questionaspnetxmlsitemapprovider does not exist in the providers collectionmemberBill - Go Steelers!24 Jun '10 - 7:43 
AnswerRe: aspnetxmlsitemapprovider does not exist in the providers collectionmemberStephen Huen24 Jun '10 - 17:42 
AnswerRe: aspnetxmlsitemapprovider does not exist in the providers collectionmemberjomungand18 Nov '10 - 4:10 
AnswerRe: aspnetxmlsitemapprovider does not exist in the providers collectionmemberlaytrix8 Nov '11 - 10:50 

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

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 15 May 2010
Article Copyright 2010 by Stephen Huen
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid