Menu SelectedItem not set for Site default pages.

Sep 19, 2007 at 5:40 PM
Edited Sep 20, 2007 at 8:25 PM
I needed to dynamically style the child navigation sections based on the selected item and some other criteria and noticed that when you link to a site, the SelectedItem property of the Menu is null. In every other case, i.e. linking to a Page, the SelectedItem property corresponds to that Page's item. Is this by design?

Resolved this by adding the following method. From RenderContents, I can call this to set the SelectedItem property.

if (Control.SelectedItem == null)

private void SetSelectedItem(MenuItemCollection items)
//When the control loads after landing on a Site's default page,
//it seems that the SelectedItem is not set. This will set SelectedItem based on the url
foreach (MenuItem item in items)
if (Page.Request.Url.ToString().ToLower().IndexOf(item.NavigateUrl.ToLower()) > 0)
item.Selected = true;
if(item.ChildItems.Count >0)
Sep 24, 2007 at 3:09 AM

I'm not sure if I understand correctly, but if you are navigating to another page, the menu control is recreated on the request and, therefore, there is no "persisted" SelectedItem object.

If you want to persist the SelectedItem property of a menu after a redirect (that's what NavigateUrl does) you should use some kind of persisting logic: viewstate, session, or even something similar to your approach in the page loading event, but not hard code it in the adapter's rendering phase.

I mean, this could be an useful "extra" feature for some people, but maybe not for others, and it's not in the original menu control, so it shouldn't be hard coded in the adapters logic.
Nov 21, 2008 at 1:53 PM
Actually this is usefull to all people that use this adapter in a moss 2007 publishing website environment... I have the same issue here:

AspNet-Menu-Selected, AspNet-Menu-ParentSelected and AspNet-Menu-childSelected are not assigned to list-items when the page you are watching is the default page of a website. Any other page you load in the same page library do result in these classes being added to various levels of your html output of the css adapter.

This results in my topnav, and leftnav not highlighting the currently active navigation element (so users have no clue where they are on the website, if you don't have a breadcrumb on your page).

Mar 25, 2009 at 11:45 AM
Edited Mar 25, 2009 at 11:48 AM
Has anyone made a solution for this problem?

For our future MOSS internet facing website we're using the AKS v2.0 and the CSSFriendly adapter. It's all up and running and sharepoint pages validates nicely, but now we strugle with the css styling.

Like psygarden wrote we're missing the AspNet-Menu-Selected, AspNet-Menu-ParentSelected and AspNet-Menu-childSelected class information on the selected items and parents.

Any input is appriciated..
Mar 25, 2009 at 1:51 PM
Edited Mar 25, 2009 at 1:58 PM
We were able to solve this by downloading the source and doing some adjustments, these have not been the only changes that we made  (we also manipulated the html output to include some span elements for specific markup with css, and made additional other changes)

Here you can find our updated solution:

Note: We are not responsible for any changes we made, use at your own risk.

      <SafeControl Assembly="CssAdapters.AdaptedControls" Namespace="CssAdapters.AdaptedControls" TypeName="*" Safe="True" />
      <SafeControl Assembly="CssAdapters, Version=, Culture=neutral, PublicKeyToken=null" Namespace="CSSFriendly" TypeName="*" Safe="True" />

This is how we use the control in the masterpage:
  <PublishingNavigation:PortalSiteMapDataSource ID="SitemapDS" Runat="server"
   StartFromCurrentNode="true" ShowStartingNode="false"/>

Hidetooltips is also a new feature, that does pretty much what it sais (no longer include tooltips for the navigation)

Kind regards,
Rik Helsen aka psygarden