Section Identifier

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
4/27/2010 5:51:03 AM
Gravatar
Total Posts 108

Section Identifier

Hi there,

I have a site with a top menu like

Home | About us | Services | News | Contact

News has 5 pages beneath it, when someone is on one of the lower pages, I'd like to retrieve the name of the top level page name that the user is in, in this case it'd like to get it to return the value 'News' which is the name of the level 1 page name.

What would be the best way to get it?

I can find the current page name with

PageSettings currentPage = CacheHelper.GetCurrentPage();

if(currentPage == null){ return; }
if(currentPage.PageTitle == "")
   lblPageName.Text = currentPage.PageName;
   else
      lblPageName.Text = currentPage.PageTitle;

But havent found a way to get the top level pagename it sites under.

Any help would be great.

Thanks

Tim

4/29/2010 9:21:24 AM
Gravatar
Total Posts 108

Re: Section Identifier

anyone? i really need to make my own custom menu for my new site going live next tuesday, i just want to find the top level pagename

4/29/2010 9:36:43 AM
Gravatar
Total Posts 18439

Re: Section Identifier

Hi Tim,

There are ways of traversing the siteMap nodes to get the topmost parent and then the parent node has the properties for page name url etc.

While I don't have time to code it up for you, you can look in the SiteMenu.ascx.cs for logic how to get the root site map node, and you can look in /Compoenents/SiteUtils.cs to see some methods where I navigate nodes in helper methods. Like you can get the current page node by calling

SiteUtils.mojoSiteMapNode currentNode = GetCurrentPageSiteMapNode(rootNode);
 

Then get the parent node with

mojoSiteMapNode topParent = SiteUtils.GetTopLevelParentNode(currentNode);

Hope it helps,

Joe

4/29/2010 10:47:14 AM
Gravatar
Total Posts 108

Re: Section Identifier

Joe thats brilliant, thank you so much.

For anyone else out there looking to display the current page name or the top page name, here is the exact code I used

namespace mojoPortal.Web.Controls
{
    public partial class imageMenu : UserControl
    {
        private SiteMapDataSource pageMapDataSource;
        private string siteMapDataSource = "PageMapDataSource";
 

        protected void Page_Load(object sender, EventArgs e)
        {

            pageMapDataSource = (SiteMapDataSource)this.Page.Master.FindControl(siteMapDataSource);

mojoPortal.Web.mojoSiteMapNode currentNode = SiteUtils.GetCurrentPageSiteMapNode(pageMapDataSource.Provider.RootNode);

menuTextCurrent.Text = currentNode.Title; // current node

mojoSiteMapNode topParent = SiteUtils.GetTopLevelParentNode(currentNode);

menuTextParent.Text = topParent.Title; // parent node

}
}
}         

You must sign in to post in the forums. This thread is closed to new posts.