A couple of problems I recently ran into is when a client said she wanted two links in the Navigation that point to the same page. Essentially what they wanted is when you click on a MAIN navigation link, it takes you to a default SubMenu link, so when you click on "Products" It takes you to the "All Products" Submenu... highlighting them both.
This was for ALL the Main menu items.
In addition she wanted some pages to be in two places, so e-news would be under products, but a link would exist in the "about us" main menu too.
This problem was solved with some creative naming in web.sitemap and a few other tricks.
Say you have a typical sitemap like so:
<sitemap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">
<sitemapnode url="~/default.aspx" title="HiddenRoot">
<sitemapnode url="~/contact/"></sitemapnode>
<sitemapnode url="~/contact/default.aspx">
<sitemapnode url="~/products/enews/"></sitemapnode></span>
</sitemapnode>
<sitemapnode url="~/products/list/" title="Our Products"></sitemapnode>
<sitemapnode url="~/products/list/default.aspx">
<sitemapnode url="~/products/where/default.aspx">
<sitemapnode url="~/products/item/default.aspx">
<sitemapnode url="~/products/enews/default.aspx">
</sitemapnode>
<sitemapnode>url="~/about/"></sitemapnode>
<sitemapnode url="~/about/default.aspx">
<sitemapnode url="~/about/qa/default.aspx">
<sitemapnode url="~/about/research/default.aspx">
</sitemapnode>
</sitemapnode>
</sitemap>
You'll notice above (in bold) that the parent nodes omit "default.aspx" IIS will take the default page when it navigates to these directories and you will actually end up at the Child Node with that actual page.
When I return Sitemap.CurrentNode() it returns the child... even though I clicked the parent. This allows me to highlight both with a CssClass dynamically (I'm using CSS friendly adapters from CodePlex for the Rendering of a MEnu Control)
Clicking : ~/about/
will take you to : ~/about/default.aspx
You'll notice that I do the same in the contact menu. The link reads /products/enews/
but the actual link in the products menu is /products/enews/default.aspx
In addition... I strip "default.aspx" off the end of ANY link in the main menu just to keep the url clean... with this code which also makes sure the Parent Node is selected :
protected void mnuNav_MenuItemDataBound(object sender, MenuEventArgs e) {
//strips default.aspx (not necessary... just for clean urls.
e.Item.NavigateUrl = e.Item.NavigateUrl.Replace("default.aspx", "");
if (SiteMap.CurrentNode != null && SiteMap.CurrentNode != SiteMap.RootNode) {
if (e.Item.Text == SiteMap.CurrentNode.ParentNode.Title)
e.Item.Selected = true;
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment