Welcome to MSDN Blogs Sign in | Join | Help

Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

The AspMenu class that ships with WSS 3.0 (and by extension MOSS 2007) is nearly identical in behavior to ASP.NET 2.0’s Menu class (as the name implies). AspMenu derives from Menu and adds tweaks to work around a few reasonably well known annoyances and provides improved highlighting support.

 

Unfortunately, this class was marked sealed and is therefore not eligible to be used as the base class for derived types. Effectively, this means that customers cannot inherit the additional functionality of the AspMenu class when trying to provide further customization of the menu.

 

We realized this problem too late in the release process and were unable to remove the sealed marker from the AspMenu class that ships with WSS. However, we are instead providing the source code for that class here (as an attachment to this blog entry) under the name MossMenu.

 

Note: MossMenu is provided as is and will only work on sites built with WSS 3.0 or MOSS 2007. MossMenu relies on some JavaScript which has been included along with the C# source. This is really just for completeness’ sake [aside: some trival about the use of the apostrophe for the possessive forms of nouns] as this script is automatically included on most pages through the core.js script include reference.

 

Issues with the ASP.NET 2.0 menu, which have been worked around:

1)     If the mouse pointer happens to be hovering over a menu item that exposes a fly-out as the page is loading, it is possible that an error dialog will appear stating: "Internet Explorer cannot open the Internet site, Operation aborted" and a blank page will be shown upon clicking OK. It seems that the problem arises from attempting to append to the DOM before it is properly initialized.

2)     If SSL termination is employed on a site with a menu, users will be greeted with “This page contains both secure and nonsecure items. Do you want to display the nonsecure items?” when hovering over a menu item which exposes fly-outs. (http://support.microsoft.com/?id=910444)

3)     In right-to-left locales, the fly-out indicator arrow still points from left-to-right.

 

Improvements to default highlighting behavior of ASP.NET 2.0 menu:

·         When hooking the menu up to a SiteMapProvider through a SiteMapDataSource, the menu automatically highlights the node that matches that returned by the provider’s CurrentNode property. However, if the particular node returned by CurrentNode is not shown by the menu nothing will be highlighted at all. The improved behavior determines if there is an ancestor of the current node which is displayed in the menu and highlights this node instead.

 

Hope this helps.

 

Chris Richard, Software Design Engineer, WCM Features

Published Saturday, December 02, 2006 5:20 PM by sptblog
Attachment(s): MossMenu.zip

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

(Crossposted from the SharePoint Team Blog .) The AspMenu class that ships with WSS 3.0 (and by extension

Saturday, December 02, 2006 12:38 PM by Enterprise Content Management (ECM) Team Blog

# WSS 3.0/MOSS 2007 Menu Control 소스코드 공개

AspMenu클래스는 사이트의 메뉴를 나타내는 컨트롤입니다. 이 클래스가 Sealed 로 봉합되어 있어서 이 컨트롤을 확장할 수 없는 상황이었는데요, MOSS팀에서 뒤늦게 문제점을

Saturday, December 02, 2006 9:37 PM by Microsoft Office Sharepoint Server 2007

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

Shame about the sealed class but thank you very much for the attached source!

Sunday, December 03, 2006 2:23 PM by Newbie

# MOSS2007/WSS v3 AspMenu Control Code Released My Microsoft!!

Microsoft have now released the source code used for the AspMenu Control that is used OOTB by both MOSS2007...

Monday, December 04, 2006 7:29 AM by hello its liam (trainbloggin)

# MossMenu source code released

The SharePoint Products and Technologies Team Blog published the MossMenu source code. The AspMenu class

Tuesday, December 05, 2006 3:25 PM by Meron Fridman's Blog

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

Is there any plans to do something similar with other components.. For example I have a customer who would like to change the "Chrome" of all webparts to have rounded corners etc.  The best way to do this in my mind is to modify the WebPartZone object.  However, it is sealed.

Wednesday, December 13, 2006 9:25 PM by Matt

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- selected item

I noticed a bug in the MossMenu code you provided: when you select as subsite in the navigation, it doesn't set the menu item as selected.

here's how I fixed this :

if (SPContext.Current.ListItemServerRelativeUrl.ToLower() == e.Item.NavigateUrl.ToLower()){

e.Item.Selected = true;}

Hope it helps

Friday, February 16, 2007 6:03 AM by nicolas

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

nicolas,

Where should the code fix should be inserted (or what code is it to replace)?

Thursday, March 15, 2007 11:20 AM by RonJez

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

oops I am sorry to have forgotten to mention that (and for the late reply)

it's in the OnMenuItemDataBound event, just after the base.OnMenuItemDataBound(e);

:)

Friday, April 13, 2007 9:57 AM by nicolas

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

We have tried to implement this code to resolve the "Internet Explorer cannot open the Internet site, Operation aborted" by creating the assembly from the c# code and referencing this code from the masterpage. Otherwise, we have not made any changes. The issue was not resolved using the code. Did we miss something? Are there other known ways to resolve or workaround this issue?

Any comments would be helpful! Thanks

Wednesday, May 09, 2007 4:36 PM by Andries

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

Our customer wanted us to use graphics instead of text for menu items.  Since most of this stuff is brand new, I was left to my own devices and came up with this customization of MossMenu.  Thought I would throw it out here for conversation, since there seemed to be no other way to set the ImageURL property for each top-level menu item in MOSS and the database did not seem to have a field in which to store one for the menu.  I added the following code to the end of the OnPreRender() event:

// BEGIN CODE SNIPPET

try

{

   bool listOk = false;

   SPWeb mySite = SPContext.Current.Site.RootWeb;

   SPList lst = null;

   try

   {

       lst = mySite.Lists["Site Collection Images"];

       listOk = true;

   }

   catch

   {

       // (do nothing)

   }

   if (listOk == true)

   {

       SPQuery qry = new SPQuery();

       qry.Query = "<Where><BeginsWith><FieldRef Name=\"Title\"/><Value Type=\"Text\">nav_</Value></BeginsWith></Where>";

       SPListItemCollection myItems = lst.GetItems(qry);

       string imgname = "";

       for (int ix = 0; ix < this.Items.Count; ix++)

       {

           imgname = "nav_" + this.Items[ix].Text.Replace(" ", "").ToLower();

           foreach (SPListItem item in myItems)

           {

               if (item["Title"].ToString() == imgname)

               {

                   this.Items[ix].ImageUrl = @"/SiteCollectionImages/" + imgname + ".jpg";

                   this.Items[ix].Text = "";

                   break;

               }

           }

           imgname = "";

       }

   }

}

catch (Exception ex)

{

   if (this.Items.Count >=1)

       this.Items[0].Text = "Menu error: " + ex.Message;

}

// END CODE SNIPPET

Deployed MossMenu to the GAC, made a custom version of master.default for our site collection that consumed MossMenu, and assigned NEWMSTR.default to the top-level site and all sub-sites.  After that, uploaded menu graphics to the Site Collection Images document library, approved all of them, and edited each one's Title property to be nav_ plus the text of the menu item (for example, nav_contactus for a Contact Us site).  (The filename of the graphic is unimportant as long as it ends in .jpg, since the Title is a separate property of the graphic in the Site Collection Images library, so there is independence from the file system naming conventions for the sites.)  New sites will automatically be assigned a graphic when the content person uploads one, approves it, and sets its Title property appropriately.

It is assumed that the MossMenu's scope is that of the site collection and that all localized versions of the graphics are stored there, which may or may not be the case.

Monday, May 14, 2007 5:34 PM by Hector Mike

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

Hector,

have you also ran into the "Internet Explorer cannot open the Internet site, Operation aborted" bug? Any ideas on how to resolve this?

Best regards,

Andries

Wednesday, May 16, 2007 8:04 AM by Andries

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

Andries,

No I have not seen it happen.  I have just tested it.  We are using IE 7.  Mine is 7.0.5730.11.  I am not sure if the IE version matters.  To learn more about it, I walked through it.  In the MossMenu C# code, a call is made in OnPreRender() to Page.ClientScript.RegisterStartupScript() after calling base.OnPreRender(), which inserts a JavaScript code fragment, which was present in the source of the page.  Looking at the JavaScript code, it looks as though it is adding a 50 millisecond delay with a call of overrideMenu_HoverStatic() in CORE.JS.  There is an amazing amount of stuff going on in here to make things happen throughout, but maybe you could modify and put an alert() call in CORE.JS to see if the override function is being called, All that said, I am not close to the authors of this code so there might be other ways to look at this.

Mike

Wednesday, May 16, 2007 10:57 AM by Hector Mike

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

Hi,

  We are facing the issue "Internet Explorer cannot open the Internet site, Operation aborted". I have replaced AspMenu control with the MossMenu control. Yet i get the IE error.

Could you please let me know if there is any other way to resolve this isssue.

Thanks

Suvarna

Thursday, July 19, 2007 4:54 PM by Suvarna

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

Hi,

I need to change the image in the Menuitems  "OnmouseOver" and "OnMouseout" events. Please let me know how to do it in the Moss Menu

         Thanks in Advance

Regards,

Jaya

Thursday, August 16, 2007 11:42 PM by Jaya

# SharePoint navigation - Make current item highlighting work

One thing that bugs me (and a lot of clients of us) is that SharePoint&#39;s top menu (AKA Global navigation

Tuesday, September 18, 2007 10:04 AM by itaysk

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

We are also fasing the problem of the error "Internet Explorer cannot open the Internet site, Operation aborted". We have replaced AspMenu control with the MossMenu control. Yet i get the IE error.  I believe the problem is IE6 related - has anyone managed to find a solution for this yet?

Thanks

Thursday, November 15, 2007 4:11 PM by Megan

# re: Customizing the Mysite

Does anyone can help me?

I developed a webpart ,this webpart can display on http://dev001/Pages/default.aspx">http://dev001/Pages/default.aspx (portal site)with no errors found but when I use the same webpart and install it to mysite page. It show "An unexpected error has occured" Web Parts Maintenance Page.

In the part souce code of my webpart connect to use the content of xml file in "C:\Program Files\Command Files\web server extensions\12\Template\Layouts\scgkm\xml\cop.xml".

symptom:

At http://dev001/Pages/default.aspx">http://dev001/Pages/default.aspx

login by SystemAdministrator : no error

login by expert01            : no error

At http://dev001/personal/admin/default.aspx">http://dev001/personal/admin/default.aspx

mysite of SystemAdminstrator : no error

At http://dev001/personal/expert01/default.aspx">http://dev001/personal/expert01/default.aspx

mysite of expert01 :error Web Parts Maintenance Page.

expert01(Privilege in http://dev001/ is member group)

I tried to solve this ploblem by trust location of "http://dev001/_layouts/scgkm/xml/cop.xml" in SharedServices1 but it still show error now.

Sunday, December 16, 2007 11:38 PM by kittiphong

# Re: Custom Menu : Display images from site collection

thanks so much for the source code to display images per subsite in teh menu.

How do I change it slightly to do mouseover and mouseout events ( in other words change my image in the menu with the mouse over event)

thanks

meg

Friday, January 18, 2008 6:08 AM by Meg

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

Hi,

Help me;

I have a sharepoint site where there is a group of users. User clicks on mysite, one of the web part displayed is the getting started web part with other few default web parts.

I want to hide/delete/close that getting started web part after a period of time(say 2 days). How best i can achive this task.

Thanx in advance.

Sreejesh.

email me: sreejuchak@gmail.com

Wednesday, January 30, 2008 6:25 AM by Sreejesh

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

Hi,I am facing the same issue of "Internet Explorer cannot open the Internet site, Operation aborted" but when I googled , I found that if there's somejavascript code written within HTML then this occurs...

But I did not find anything in my code.

Now I got a solution to this issue i.e by replacing RegisterStartupScript by RegisterClientScriptBlock..But this leads to some other minute issue...Can someone please suggest me if I am going the right way?

Monday, June 02, 2008 9:41 AM by Jitesh

# re: Customizing the WSS 3.0/MOSS 2007 Menu Control -- MossMenu source code released

Hi, I have found a bug in MossMenu.

When MapProvider have more than one level of depth, MossMenu don't work correctly. Only shows the first element.

Any idea? solution?

Thanks.

Wednesday, February 18, 2009 11:17 AM by quintorel

# Custom Navigation in SharePoint - The Full Monty

The out of the box navigation controls work for many scenarios, but what happens if they don't? What

Monday, March 09, 2009 6:27 AM by Michael O'Donovan's SharePoint and Stuff

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker