in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

This Blog

Syndication

Tags

No tags have been created or used yet.

Archives

anchorpoint's blog

Tab highlighting in Top Navigation Bar

In a solution I'm building I was met with the task of creating a web site programmaticly and no sweat I thought. The site creation itself was a breeze, but I wsa met a bit of a challange when trying to create navigation tabs.

The parent web site would have a tab on the top navigation bar pointing to the new web site, and the newly created web site would have a tab as well that was highlighted in the top navigation when the user was visiting the site.

No problem I thought again. So I happily went and created the tab to the new site on the parent web site and told the newly created website to just inherit navigation. But to my surprise the tab on the newly created site was not highlighted when I was visiting it. This kinda puzzled me.

I had told the top navigation bar of the parent web site to use this node:

SPNavigationNode navigationNode = new SPNavigationNode("My Web Site", "/MyWebSite");

But apparently that wasn't enough to highlight the tab.

After some more efford I finally figured out that it had to be:

SPNavigationNode navigationNode = new SPNavigationNode("My Web Site", "/MyWebSite/default.aspx");

Yeah .. you have to remember default.aspx. Anyway the code to create a child web site with parent top navigation and tab highlighting would be:

using (SPSite site = new SPSite(siteUrl))

{

using (SPWeb web = site.AllWebs.Add("/MyWebSite", "My Web Site", "", 1033, "STS#1", false, false))

{

SPNavigationNode navigationNode = new SPNavigationNode("My Web Site", "/MyWebSite/default.aspx");

SPNavigation navigation = web.ParentWeb.Navigation;

SPNavigationNodeCollection topNavigationNodeCollection = navigation.TopNavigationBar;

topNavigationNodeCollection.AddAsLast(navigationNode);

web.Navigation.UseShared = true;

web.Update();

}

}

Happy SharePoint hacking.

Comments

 

Chirag Darji said:

Hi,

  I want to add my own tab in top navigation menu. I want that every page in site has three tab on top menu. 1. "Home" 2. "Custom1" and 3. "Cusom3". It will be highly appriciated if you can help me this.

October 17, 2007 7:52 AM
 

Orfeo said:

I found that for proper highlighting of the tabs, it is not necessary to add the filename like default.aspx to the link if the site is in the same sitecollection. When you type in the link, it won't highlight, but if you use the 'browse' button next to the link field, which presents the 'Select a link -- Web page dialog' and browse for any available site or page, that will result in proper highlighting.

I am ever so happy that I found this (by trial and error)

January 1, 2008 6:15 PM
 

jeevabharathy said:

hai

July 10, 2008 9:59 AM

Leave a Comment

(required )  
(optional )
(required )  
Add

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts