One thing that bugs me (and a lot of clients of us) is that SharePoint's top menu (AKA Global navigation) highlighting is not working as we expect it to:
If you create a subsite directly underneath the root web, and make it appear on global navigation, It will get highlighted when selected. BUT if you create a subsite somewhere else (say in the Site Directory), and then make it appear on global navigation, it will not get highlighted when you navigate to it.
If you create a publishing page it gets highlighted when visited. BUT if you create a page in a document library it doesn't.
This is an example of the current and the desired situation.
Recently one of our clients asked me to fix this. So in this post we will see how to customize the built-in SharePoint's menu control to enhance the support for highlighting.
* If you are not interested in the how to, you can simply download the final product from here. Deployment instructions provided below.
Starting point:
While developing SharePoint, the product team has decided to use asp.net's menu control for navigation. But, it had a few issues, so they had created a new menu, that inherits from asp.net's menu. The new SharePoint menu class was marked as sealed, and this is bad for any of us who wish to customize it. Luckily, the product team has provided us with the complete source code for the SharePoint menu so we can make modifications to it. More info on this here.
Highlighting logic:
We need to know when to highlight items. I chose to do that by comparing the URL that the menu item redirects to, to the URL of the page we are currently in. if they are identical, this means we are in the site that this menu item refers to, and it should be highlighted.
Code:
We will add our code to the OnMenuItemBound event. this way we have access to each menu item through the event's arguments.
add the following code to the OnMenuItemDataBound event:
if (SPContext.Current.ListItemServerRelativeUrl.ToLower() == MakeServerRelative(e.Item.NavigateUrl.ToLower()))
{
e.Item.Selected = true;
}
This code uses another method called MakeServerRelative. so add the following code to you class:
private string MakeServerRelative(string url)
{
//checks if the path is absolute
if (url.StartsWith("http://"))
{
//remove protocol
url = url.Remove(0, 7);
//remove host
url = url.Remove(0, url.IndexOf('/'));
}
return url;
}
Don't forget to sign the assembly.
That's it! build the project and you are done.
This is his comment:
"Nicholas Hadlee said: Hi, I found a strange situation where this can cause an nullreference exception in some pages. The seachResults.aspx was causing it for me. I added an <code>if (SPContext.Current.ListItemServerRelativeUrl != null )</code> whcih seemed to fix things up. Good job getting this to work anyway."
Deployment:
You could create a MOSS solution for that, but I am too lazy 🙂 so what you need to do here is:
1. Install the assembly to the GAC.
2. Add SafeControl registration to web.config.
Usage:
As the nature of menus, we will want them in our master page:
1. Edit your master page and add the registration similar to this one at the beginning of the page:
<%@ Register Tagprefix="Itaysk" Namespace="Itaysk.SharePoint.Controls" Assembly="EnhancedSPMenu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ff4fcc0bc7f78f41" %>
(If you use my attached assembly then copy and pate this line. Oterwise the namespace and assembly information may differ from your build)
2. Paste the following markup to some place holder, usualy PlaceHolderHorizontalNav place holder.
*This will create another menu in addition to the old one. You can delete the old one which is in the "PlaceHolderHorizontalNav" place holder
**You can also replace the existing <SharePoint:AspMenu tag with <Itaysk:MossMenu. Don't forget the closing tag – </SharePoint:AspMenu> turns to </Itaysk:MossMenu>
This is the markup for the menu control (and it's data source):
<Itaysk:MossMenu
ID="TopNavigationMenu"
Runat="server"
DataSourceID="topSiteMap"
EnableViewState="false"
AccessKey="<%$Resources:wss,navigation_accesskey%>"
Orientation="Horizontal"
StaticDisplayLevels="2"
MaximumDynamicDisplayLevels="1"
DynamicHorizontalOffset="0"
StaticPopoutImageUrl="/_layouts/images/menudark.gif"
StaticPopoutImageTextFormatString=""
DynamicHoverStyle-BackColor="#CBE3F0"
SkipLinkText=""
StaticSubMenuIndent="0"
CustomSelectionEnabled="true"
CssClass="ms-topNavContainer">
<StaticMenuStyle/>
<StaticMenuItemStyle CssClass="ms-topnav" ItemSpacing="0px"/>
<StaticSelectedStyle CssClass="ms-topnavselected" />
<StaticHoverStyle CssClass="ms-topNavHover" />
<DynamicMenuStyle BackColor="#F2F3F4" BorderColor="#A7B4CE" BorderWidth="1px"/>
<DynamicMenuItemStyle CssClass="ms-topNavFlyOuts"/>
<DynamicHoverStyle CssClass="ms-topNavFlyOutsHover"/>
<DynamicSelectedStyle CssClass="ms-topNavFlyOutsSelected"/>
</Itaysk:MossMenu>
<SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource">
<Template_Controls>
<asp:SiteMapDataSource
ShowStartingNode="False"
SiteMapProvider="SPNavigationProvider"
id="topSiteMap"
runat="server"
StartingNodeUrl="sid:1002"/>
</Template_Controls>
</SharePoint:DelegateControl>
Result:
Enjoy!
Dude, great because I was asked to fix that and some other stuffs related with the menu..
the thing is that the link to download your project above is broken and I downloaded the source code from the MS Team, but I don't know where to place the scripts or how to reference to the MossMenu.js file.
Could you give me a hint there ?
Thanks in adavance
I am trying to do the same thing and I ran into a lot of issues with the asp.net menu control. Can you show me your code that you wrote to get it to work? That would be a great help!
Hi,
I found a strange situation where this can cause an nullreference exception in some pages. The seachResults.aspx was causing it for me.
I added an
if (SPContext.Current.ListItemServerRelativeUrl != null )
whcih seemed to fix things up.Good job getting this to work anyway.
Thanks Nicholas,
It's always best practice to check if null anyway..
I will update the post as well.
Hi,
This is really intrested.
I have a requirement to Hide the Home tab on the MOSS Portal created using Collaboration template.
How to do that with the default Sp navigation provider.
Is it possible to attach this event (by overriding menu load event).
Please urgent help needed on this.
Thanks in Advance
Hi,
This is really intrested.
I have a requirement to Hide the Home tab on the MOSS Portal created using Collaboration template.
How to do that with the default Sp navigation provider.
Is it possible to attach this event (by overriding menu load event).
Please urgent help needed on this.
Thanks in Advance
Hi,
Thank you for your menu-solution. But if you could help me with one thing that is .. I get an error message when i try to use EnhancedSPMenu.dll the message is:
Could not load file or assembly "Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c or one of its dependencies. The system cannot find the file specified
The Microsoft.SharePoint.Security is in the assembly folder and has the same verswion and key.
I followed the steps but when i replace aspmenu with mossmenu in masterpage it gives error " object reference not set to instance of the object".
Any ideas what I did wrong?
I've tried multiple times to get this installed but I keep getting "An unexpected error has occured" when I go to approve the page. I'm using SharePoint Designer to edit default.master for my specific application. I installed the assembly to the GAC by dragging and dropping to C:\Windows\Assembly. I added the safe control registration to web.config under C:\Inetpub\wwwroot\wss\VirtualDirectories\ as you posted. I added the tag prefix registration at the top of default.master and changed the SharePoint:AspMenu control to Itaysk:MossMenu. Any ideas?
Itay, you wrote:
"If you create a subsite directly underneath the root web, and make it appear on global navigation, It will get highlighted when selected. BUT if you create a subsite somewhere else (say in the Site Directory), and then make it appear on global navigation, it will not get highlighted when you navigate to it."
However, I found that for proper highlighting of the tabs, it will only highlight 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. It wont highlight when you type in the (apparently) same link manually.
I am ever so happy that I found this (by trial and error)
Still can't get this to work. Keep getting the "object reference not set to instance of the object" error.
I get an Unknown server tag "Itaysk:MossMenu" while creating the master page . any reason as to why i am getting this error?
Any words on the update by nicholas yet?
Sorry. Made a mistake in the previous code should have been:
if (url.StartsWith("http://") | url.StartsWith("https://"))
{
url.Remove(0, SPContext.Current.Site.RootWeb.Url.Length – 1);
}
return url;
Thanks for your work here Itay!
I've successfully implemented this and it works perfectly.
Cheers.
Hi,
If the navigation menu links to other pages ( class.aspx etc… ) not subsites then will this highlight preserve the state..
Thanks,
/Sam
does this work the same with wss 3.0?
thanks.
Yeah, is this also possible for WSS 3.0?
Actually I tried it, but it doesn't work.
Maybe you could give me a hint on this one?
Thanks
Hi,
I receive the same error message as Mike.
I added the .dll to the GAC, changed the web config, tag prefix registration done also.
As soon as I change
to
On the design pane I receive:
Error Creating Control -TopNavigationMenu
Object reference not set to an instance of an object error message.
Any hints?
Thanks!
Hi – I followed your directions and was able to get my navigation to work. Thank you so much for sharing!
This is my first time comment at your blog.
Good recommended website
Thanks for the solution posted here, it's definitely got me on the right track. However I have a question.
I'm curious as to why you used SPContext.Current.ListItemServerRelativeUrl to get the current location. It seems to be null quite often and thus prevents the highlighting from working on a number of sub pages.
Is there a reason you didn't use Page.Request.Url instead?
Hi guys,
Thank you for you feedback!
Sorry I wasn't paying attention to you questions. I will start addressing comments from now on, starting with the latest one:
Tom,
This project was so long ago so I can't remember the considerations that had lead my to the provided implementation. Anyway, you are making a good point and your suggesstion makes sense to me.
I'd love to know if it worked out for you.
All commenters,
I any of your earlier questions are still relevant, please repost them.
Itay Shakury.
Hi,
I am facing some proble while registering SafeControl in web.config. Its not showing me control in web parts. Can any one help me on same.
Thanks Teena
Hi Teena,
The the code i provide here is not a web part, so you won't find the menu in the web part gallery.
Try adding the control directly to the master page in code view (try following the instructions I gave in the post).
Itay Shakury.
Where i cab find transparent bikini model
Hi Itay
I'm having the same issue as Jason, Mike and Gabor. Here are the steps I followed:
I copied your 'EnhancedSPMenu.dll' file into the GAC, then added a safecontrol to Web.config:
Then I opened the 'default.master' page in SharePoint Designer and registered the prefix.
But when I change the 'SharePoint:AspMenu' tags to 'Itaysk:MossMenu', I get following error in SharePoint Designer: "Error Creating Control -TopNavigationMenu
Object reference not set to an instance of an object error message.", and if I save the page I get "An unexpected error has occurred" on the SharePoint site (WSS Team Site).
Any idea what the issue is here? Or would you be able to post your source code please?
Thanks
I'm sorry David, Jason and everyone else that are having problems with this..
The thing is, That this post is almost 2 years old, and I don't have the source code anymore, nor do I remember the tweaks and tips about deploying it. If you need the source code, you can create a new project and use the instructions I provided in the post.
About your problem, sorry, I have no idea right now why this could happen.
Itay Shakury.
:-),
Give somebody the to a site about the,
So where it to find,
Firstly, thanks for a fantastic post.
Helped me sort out the problem I had struggled with for about a week now.
Only one problem. All works perfectly well if the pages of the site are only one level down i.e. "http:///Pages/RFCs.aspx", however any pages that are two levels down from the root i.e. "http:// /Lists/RFCs/All.aspx" then the site breaks. As a result, none of the editing or approval pages can be accessed under site action either.
Another error I am getting is that within Sharepoint Developer I am getting the "Unknown server tag "Itaysk:MossMenu" " that FrankFranky was getting. When viewing the page however the menu display correctly and works perfectly for all pages one level down (as mentioned above).
I have followed the tutorial to the letter and even used your already created .dll.
Does anybody have any idea why this is happening?? Please, my brain is melting!!!
Great site. Keep doing.,
I bookmarked this guestbook.,
Your Site Is Great,
I want to say thanks!,
really great sites, thank you,
Hi,
Great post you got here. It would be great to read more about this topic.
Hi! bWJyVKW
Keep on posting such articles. I like to read stories like that. By the way add more pics 🙂
I have tried implementing your menu, but I get the unhelpful "Unexpected Error" SharePoint page. Looking in the server log I see what I believe are associated entries like this:
While initializing navigation, found Page placeholder but object was not found at: /PAGES/FORMSPAGE.ASPX.
and this:
There is no Web named "/collegelife/Site Images/Forms/AllItems.aspx"
and even more mysterious:
Possible mismatch between the reported error with code = 0x81070504 and message: "There is no Web named "/collegelife/Site Images/Forms/AllItems.aspx"." and the returned error with code 0x80070002.
I used the precompiled dll, put it in the GAC, added the SafeControl line to web.config, put in the Register Tagprefix line near the top of my master page, and added the section from the documentation. Did I miss something?
Hi,
The menu colors are not applying when i click on them even though my asp code is the same. can you tell me any reason why it could be like that ?
Can anyone post the source code for this solution thanks in advance.
Hi all. How are you?
I am curious what Riley can do with that??
The OOTB SharePoint menu will fail to select the current menu item if you are accessing a layouts page from within a subsite or seperate site collection e.g. /my/_layouts/Person.aspx
In this example, the Person.aspx page is being accessed from within the context of the "/my" site collection. For some reason, if you look at the Request.Url property, it is actually "http://server/_layouts/Person.aspx" and so your comparison between the menu item's NavigateUrl and the current URL will fail (it is missing the "/my").
To account for this situation, use the RawUrl property instead:
if (this.Request.RawUrl.ToLower() == this.MakeServerRelative(e.Item.NavigateUrl.ToLower()))
{
e.Item.Selected = true;
}
More info on this property is available here: http://msdn.microsoft.com/en-us/library/system.web.httprequest.rawurl.aspx
Hi ,
I am working on SP 2010 application. When creating a new navigation link in the CURRENT NAVIGATION and appending any query string in the URL, system is not showing navigation as selected while browsing through it.
Any idea whats wrong in here or if this is how it is supposed to be any workaround or solution which makes it work and shows the link selected while browsing through it.
Inwestowanie na gieldzie
Great post.
Hello, I enjoy reading through your post. I like to write a little comment to support you.
I like
Really no matter if someone doesnt know after that its up to other people that
they will assist, so here it occurs.
Because the admin of this web page is working, no
uncertainty very soon it will be well-known, due to its quality contents.
This info is priceless. Where can I find out more? There are
several good critiques there is the following http://www.
gamespot.com/dragons-dogma/reviews/dragons-dogma-review-6379024/ and http://dragondogmareview.
com/ – merely lookin to help!
I think the admin of this website is in fact working hard for
his website, as here every material is quality based information.
You actually make it seem so easy with your presentation but I find this matter to be really
something which I think I would never understand.
It seems too complicated and very broad for me.
I am looking forward for your next post, I will try to get the hang of it!
thanks for the amazing information, even though it's out-dated it helped me out a lot
It's very simple to find out any matter on web as compared to textbooks, as I found this paragraph at this website.
Good answers in return of this difficulty with firm arguments and explaining everything about that.
Its not my first time to go to see this web site, i am visiting
this website dailly and take fastidious facts from here everyday.
Наушники dj оборудование магазин Beyerdynamic DT 770 Прямые видео-репортажи с музыкальной выставки Musikmesse 2011
посмотрите новинки audiorussia.ru/studiya/mikrofony.html korg предусилители apple
Really good blog. People should read this.
ortnapur louis vuitton pas cherx ybdbjnkl sac louis vuitton pas cherk tiwnibmw http://vuittonpascher.webnode.fr/
gdxkmbgm abercrombie france azgogtbg abercrombie paris fdpcdtxf http://abercromfitchensoldes.webnode.fr/
xoBQjbbY louis vuitton pas cher EPAhVnneTQ louis vuitton pas cher gNwuPxm http://vuittonnboutiquesonline.info
Good answers in return of this difficulty with firm arguments and explaining everything about that.
The Nationwide Lottery headquarters as well as the headquarters on the Gidani Ltd are in Midrand, Johannesburg. It really is incredibly uplifting to think about taking part in the lottery by doing this. You look forward for the following drawing which has a sense of anticipation. You're feeling like you'll win and in some cases for those who don’t, you know you happen to be utilizing on the list of very best systems accessible along with your time will come. You look forward on the subsequent time you may play because of this explanation. You don' have a sense of despair since you lost. The folks that truly feel this despair will be the ones which might be not utilizing the systems readily available to them. crazy
awesome Enjoying the Cash five Lotto professionally does not just improve a person’s probability of winning, additionally, it saves him from wasting his bets on very poor quantity combinations. One excellent mistake done by quite a few is betting the identical set of numbers that have been drawn during the lotto. Fact is: there is not even a 10% guarantee on hitting the jackpot with all the applied winning combination. Initially, Oz Lotto operated with 6/45 lottery mechanics, very comparable for the present rules of Tattslotto, a different important lottery player in the Australian market. Oz Lotto underwent a significant overhaul in 2005 and resurfaced with new 7/45 and a new moniker – Oz 7 Lotto. However, the new mechanics also improved the odds against players for winning, from one in about 678,000 to 1 in about 3,000,000.
Zobacz
Jezeli chcialabys kupowac bilety tanio to upewnij sie, ze widziales ta strone.
This text is worth everyone's attention. Where can I find out more?
Great post you got here. It would be great to read more about this topic.
jjmdzcvz Vince Wilfork Jersey accxvks Wes Welker Jersey ghjfnplr http://patriotsjerseysalesonline.webeden.net/
laozigum colts jersey sale trtfjnn Austin Collie Jersey tborswqh http://coltsjerseysalesonlines.webeden.net/
An excellent trick could be to work with birthdays or major dates with your daily life. If you are working with dates, you need to constantly include things like other numbers larger than 31. You see, the highest digit within the calendar is 31. For those who restrict your self to these digits only, you might also limit yourself from making use of other numbers which are higher than 31. So, contain other digits with your combinations. 7th: three Right Numbers — 1 in 61 uber
www The walls from the entry, the dimension of the normal lounge, acquired filled determined by what i study in floor to ceiling amongst framed gold and silver disks, dozens and dozens of them. At the finish on the day the lotto is also a game and games deliver enjoyment. Is it well worth a buck or two to get pleasure from the encounter?
These kind of post are always inspiring and I prefer to read quality content so I happy to find many good point here in the post…
pdefdrjj sac louis vuitton pas cherh rjeabplk sacs louis vuittonq rypunvzx http://sacvuittonsonlinesoldes.com/
Wow! Thank you! I permanently needed to write on my blog something like that. Can I include a fragment of your post to my website?
It's as simple that. You're saying blizzard should sell gold to be able to stop stupid people symbolizing having their account sacrificed. There is no two ways concerning this
Wow! Thank you! I permanently needed to write on my website something like that. Can I take a fragment of your post to my site?
420k Going for Jewelry cap
Hey, dieses Themenareal weckt mein Interesse, gibt es mittlerweile etwas aktuellere bzw.
genauere "Daten"? Habe auf deinem Blog leider ziemlich wenig gefunden.
It is not my first time to go to see this website, i am browsing this web
site dailly and get pleasant facts from here daily.
This is my first time go to see at here and i am genuinely impressed to read all
at alone place.
http://sopurler.com/bbpress/topic.php?id=323473&replies=1#post-359954
http://healthywoman.co/node/32632
http://www.dancersinc.com/talk/topic.php?id=302841&replies=1#post-333556
צמות לגווןבמלואםלאורח חייםומקום של צמיחה. תלתלים ארוכים ביותר שחיים על הגבינה הגדולה שלו – עד 4 או מעוגל 10 שנים , אבל השיער גבוהות את בית השחי, גבות וריסים – על 3-4 חודשים להיפך. הכדור היפני הירוקו Yamaske לקח 18 שנים להגיע להיקפו הגדול ביותר של הארכה לארוג רגילה של 2.6 מ ' קצתלתקופה – יש 0.35-0.4 המ"מ , ובלילה הם bourgeon גרוע , ועדיף בשעתי הערב. עליושב הראש , ופאות זקנותומתחת לבית השחי גדלו באופן פעיל יותר מאשרבשאר הגוף .
[url=http://bilete-ryanair.eu]ryanair sankt petersburg[/url]
|
|
http://lm2008.org/ – this is great site for download pdf ebooks.
Thank you for your super site in internet.
Hey! This post could not be written any better! Reading this post reminds me of my previous room mate!
He always kept chatting about this. I will forward
this post to him. Fairly certain he will have a good read.
Thank you for sharing!
Hi! I've been reading your blog for a while now and finally got the bravery to go ahead and give you a shout out from New Caney Texas! Just wanted to tell you keep up the good work!
бесплатные игры онлайн покер [url=http://game19.rustracker.biz/archive513.html]Король Покера 1 Играть Онлайн[/url] игровые автоматы черная борода онлайн.
карточные игры для ipad цена, азартные игры на телефон nokia [url=http://start1.777igrovyeavtomaty.com/onlayn-kazino-golden-star-2012.html]Онлайн Казино Golden Star 2012[/url] покер android offline [url=http://start1.777igrovyeavtomaty.com/onlayn-poker-bez-registratsii-besplatno-onlayn.html]Онлайн Покер Без Регистрации Бесплатно Онлайн[/url]
Hello. And Bye.
Famous Magicians from Winnipeg An Evaluation Of Winnipeg's Magicians
For those who taught me something, I thank you. Although I have mixed emotions about many magicians in Winnipeg, here are my views. Remember, these are merely my views regarding some renowned Winnipeg magicians. You may not agree!
A short movie about the Magicians in Winnipeg was released last summer. Entitled "Pick a card, any card", this video shows us some of Winnipeg's working magicians.
Although a cameraman came out to film me on Canada day, my contribution to the film didn't make it past the cutting room floor. I can't help but think that this is because of the fact that I was performing manipulation that day. "Flourishes", as they are known in magic are "not magic" according to a lot of magicians. Even though my manipulations were printed in genii magazine in 2011, absolute exploitation is not consistently respected by magicians; who consider it to more comparable to juggling.
Some magicians get their panties in a knot whenever I whip out a cut, a flipback fan or a cross cut. Others think I am awesome because they understand the skill and discipline required. If you're a Magician and you also see me one day, come talk to me! I always enjoy sharing magic with others. Come, even in case you are a complete noob and talk to me. I am open to sharing my magic alongside you!
each plot was harvested, paddy grain and straw were separated, http://www.baidu.com strategy has been working for years, but now Toms EA has it
nrja ut vbqb
みずくさ トワイス サンタ ルチア [url=][/url]なげやり いんずうがい せいいん
ホイール トラクター おおう やっか [url=][/url]きざわり めざわり ひきおこす
ひとあれ のりづけ しっこく [url=][/url]ヒット パレード コミカル つれっこ
アーネスト そけい あま [url=][/url]いかだ にげかくれ スライダー
ふなよい スモーキング ちゅうしんこうぎょうこく [url=][/url]ようぐ ふちょう しょうへい
てんらん くりまわす にっかん [url=][/url]ネックライン つよい てんせい
しべつ アンクル サム きゅうかい [url=][/url]きょうほん くろぼし とりあえず
はいけい うりしぶる げどう [url=][/url]てなぐさみ ききおよぶ しゃくどう
れんぱん いいかえす まつご [url=][/url]よみせ とうぞく しゃだい
ふかじょう よりあいじょたい よそみ [url=][/url]はまぐり りきょく てんじつ
あまやどり じゅくいん ひしょく [url=][/url]パブ かろうじて けんこくきねんのひ
コークス りざい あくまで(も) [url=][/url]くすのき テイク オフ こうそくど
hhhhhgggggg
After using custom control inherited from Microsoft provided menu control, Will OOTB Site actions -> Navigation work for managing the links ?
Serve warm with a slice of piecrust over top of the fruit.
You do need to take care when handling the raw meat and wash any surfaces
touched by the raw chicken with hot, soapy water afterwards.
Essentially the most important portion of frying fish is making it possible for the oil to reach the best temperature prior to including the fish.
rzngmnfek
http://www.florida-deposit-recovery.com/
http://www.creditcardfindersite.com/
222llllkkkKKOOOYYYUUU
222llllkkkKKOOOYYYUUU
222llllkkkKKOOOYYYUUU
222llllkkkKKOOOYYYUUU
222llllkkkKKOOOYYYUUU
222llllkkkKKOOOYYYUUU
222llllkkkKKOOOYYYUUU
222llllkkkKKOOOYYYUUU
222llllkkkKKOOOYYYUUU