Ask a questionAsk a question
 

AnswerActivating NavBarLink defined in Onet.xml progmatically

  • Monday, November 02, 2009 5:28 PMLandy_Mic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hello All,
    I have a ASP.NET based application that is running under Sharepoint/Moss 2007.
    Top NavigationMenuBar is done with Onet.xml.  Application contains multiple Site Collections and some times
    focus is not updated properly in NavigationMenuBar.

    So how is it possible to activate certain NavBarLink programatically from CodeBehind?

    Something like below .. but how to activate the NavBarNode?

    SPSite oSiteCollection = SPContext.Current.Site;
    SPNavigationNode navBarNode = oSiteCollection.Navigation.GetNodeByUrl("/mySitec/app1");
    navBarNode. <how to set this NavBarLink active????

    Cheers,

    Michael

Answers

  • Wednesday, November 04, 2009 1:49 AMCharlie WuModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hello All,
    I have a ASP.NET based application that is running under Sharepoint/Moss 2007.
    Top NavigationMenuBar is done with Onet.xml.  Application contains multiple Site Collections and some times
    focus is not updated properly in NavigationMenuBar.

    So how is it possible to activate certain NavBarLink programatically from CodeBehind?

    Something like below .. but how to activate the NavBarNode?

    SPSite oSiteCollection = SPContext.Current.Site;
    SPNavigationNode navBarNode = oSiteCollection.Navigation.GetNodeByUrl("/mySitec/app1");
    navBarNode. <how to set this NavBarLink active????

    Cheers,

    Michael


    No such property or method associate with SPNavigationNode.
    All the members of this class is listed:
    SPNavigationNode Members (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.navigation.spnavigationnode_members.aspx)

    JavaScript seems the mostly likely solution. You need a step further to make all the highlighted item back to normal.
    And the highlight the entry you wish.

    The normal css class are:
    zz1_TopNavigationMenu_1 ms-topnav zz1_TopNavigationMenu_3
    Keep It Simple and Stupid.
    • Marked As Answer byLandy_Mic Wednesday, November 04, 2009 7:13 AM
    • Unmarked As Answer byLandy_Mic Wednesday, November 04, 2009 6:35 PM
    • Marked As Answer byLandy_Mic Thursday, November 05, 2009 5:24 PM
    •  

All Replies

  • Monday, November 02, 2009 7:05 PMCharlie Holland Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Michael,

    Not sure what you mean by focus, if you're talking about the focus for the enter key etc then I think you'll need to use some javascript to do this. The SPNavigationNode represents the data thats behind the menu rather than the menu itself. The menu control is just a slightly modified asp.net menu that uses the SPNavigationNodes as a datasource.

    Are you doing any other processing on the menu? adding/removing nodes and such like, on the fly?




    Ch. - My Blog
  • Tuesday, November 03, 2009 8:46 AMLandy_Mic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello,

    Okey I try to clearify. Like I mentioned we use in our Application onet.xml based TopNavigationbar. Our Application is using ASP.NET technology for User Interface together with SharePoint technology.

    ASP.NET part of the Application is shared into 5 different SiteCollections but they have same TopNavigationBar. As I mentioned sometimes focus is dissapearing from current Item in TopNavigationBar indicating which ASP.NET Site is active.

    Thats what I would like to fix.

    I'm not doing any other processing like adding/removing to the menu.

    I also coded and tested Javascript like below

    // Number refers which menuiten is highlighted
    function ActiveTopBarMenu(Number)
    {
    var tlbeTd = document.getElementById("zz1_TopNavigationMenun"+Number);
    var tlbeTable = tlbeTd.getElementsByTagName('table');
    tlbeTable[0].className = 
    "zz1_TopNavigationMenu_1 ms-topnav zz1_TopNavigationMenu_3 ms-topnavselected zz1_TopNavigationMenu_9";
    }

    but problem is that it leaves the previously selected item highligted ...

    Has anyone any ideas how to handle this kind of issue?

    Br

    Michael
  • Wednesday, November 04, 2009 1:49 AMCharlie WuModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hello All,
    I have a ASP.NET based application that is running under Sharepoint/Moss 2007.
    Top NavigationMenuBar is done with Onet.xml.  Application contains multiple Site Collections and some times
    focus is not updated properly in NavigationMenuBar.

    So how is it possible to activate certain NavBarLink programatically from CodeBehind?

    Something like below .. but how to activate the NavBarNode?

    SPSite oSiteCollection = SPContext.Current.Site;
    SPNavigationNode navBarNode = oSiteCollection.Navigation.GetNodeByUrl("/mySitec/app1");
    navBarNode. <how to set this NavBarLink active????

    Cheers,

    Michael


    No such property or method associate with SPNavigationNode.
    All the members of this class is listed:
    SPNavigationNode Members (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.navigation.spnavigationnode_members.aspx)

    JavaScript seems the mostly likely solution. You need a step further to make all the highlighted item back to normal.
    And the highlight the entry you wish.

    The normal css class are:
    zz1_TopNavigationMenu_1 ms-topnav zz1_TopNavigationMenu_3
    Keep It Simple and Stupid.
    • Marked As Answer byLandy_Mic Wednesday, November 04, 2009 7:13 AM
    • Unmarked As Answer byLandy_Mic Wednesday, November 04, 2009 6:35 PM
    • Marked As Answer byLandy_Mic Thursday, November 05, 2009 5:24 PM
    •  
  • Wednesday, November 04, 2009 7:13 AMLandy_Mic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello Charlie and thanks for your reply!

    Yes, I will try this Javascript approach to TopMenuBar.

    Br

    Michael
  • Wednesday, November 04, 2009 6:42 PMLandy_Mic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello All again,

    I have struggled with this issue and I found a code snippet from CodePlex (spsiteconfigurator) which had a folowing method.

    protected static void UpdateNodeProperty(SPNavigationNode node, string propertyName, object value)
    {
       if (node.Properties.Contains(propertyName))
           node.Properties.Remove(propertyName);
       node.Properties.Add(propertyName, value);
       node.Update();
    }

    Could this be a way to activate wanted menuitem in TopNavigationBar?

    I tried to find out propeties of the SPNavigationNode but didn't succeed to find anything in the Web.

    Has anyone better knowledge about SPNavigationNode's propeties and about setting it selected/highlighted?

    Thanks,

    Michael
  • Thursday, November 05, 2009 1:25 AMCharlie WuModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I'm afraid the property is a hash table with the following name-value pair:

    Property                          Value
    vti_navsequencechild        true
    CreatedDate                    6/23/2009 5:47:59 AM
    UrlQueryString       
    NodeType                        Area
    Audience       
    Target       
    Description                     Document Center site
    LastModifiedDate             6/23/2009 5:47:59 AM
    UrlFragment       

    NOTE: THIS IS SAMPLE VALUE.


    You can try retrieve the name-value pairs with the following code:

        using (SPSite site = new SPSite("http://localhost/"))
        {
            using (SPWeb web = site.RootWeb)
            {
                SPNavigationNodeCollection topNav = web.Navigation.TopNavigationBar;

               
                foreach (object k in topNav[0].Properties.Keys)
                {
                    Console.WriteLine("{0}: {1}", k.ToString(), topNav[0].Properties[k].ToString()); 
                }
            }
        }

    As far as I can tell, no name-value pair can help you with your requirement.
    JS is promising so far.
    Keep It Simple and Stupid.
  • Thursday, November 05, 2009 5:23 PMLandy_Mic Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello and thanks again Charlie!

    It seems to be so that Javascript solution is only way to do it.

    By the way do you or anybody else know that if it's possible to handle this kind of TopNavigationBar's menu highlighting somewhere in WebApp's (ASP.NET) or Sharepoint's IHTTPHandler or other centralized place?
    What could be the best place to insert this kind of code?

    Br,

    Michael
  • Friday, November 06, 2009 3:54 AMCharlie WuModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Find a convinenet place, just make sure it does not interfere with the default ones.


    Keep It Simple and Stupid.