On our site we have a top menu, and a side menu. Other than using the same sitemap, they don't have any other relationship.
On the top menu, we only show the top links, with 0 child nodes, which is what we want.
On the side menu however, we want to show all the child pages when someone hovers over the main links. Some have up to 12 child nodes, and some only 1.
Our challenge is hiding a couple of specific pages from that menu.
An example is a "thanks for contacting us" page which is under the main "contact us" page. Otherwise, a person can hover over the contact page link and see the "thanks" page as a link - and we don't want people going directly to the thanks page. So, we
want just "Contact" to show in that menu, no matter where a visitor is in the site.
I have tried a couple of solutions but they haven't worked. Is there an easier way to hide them?
Object reference not set to an instance of an object.
Description:An
unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details:System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 26: {
Line 27: //mnuNavMenu.Items.Remove(e.Item);
Line 28: e.Item.Parent.ChildItems.Remove(e.Item); Line 29: }
Line 30:
DavidLee
Member
65 Points
45 Posts
Hide a certain child node only.
Jan 28, 2010 05:18 PM|LINK
Hi,
On our site we have a top menu, and a side menu. Other than using the same sitemap, they don't have any other relationship.
On the top menu, we only show the top links, with 0 child nodes, which is what we want.
On the side menu however, we want to show all the child pages when someone hovers over the main links. Some have up to 12 child nodes, and some only 1.
Our challenge is hiding a couple of specific pages from that menu.
An example is a "thanks for contacting us" page which is under the main "contact us" page. Otherwise, a person can hover over the contact page link and see the "thanks" page as a link - and we don't want people going directly to the thanks page. So, we want just "Contact" to show in that menu, no matter where a visitor is in the site.
I have tried a couple of solutions but they haven't worked. Is there an easier way to hide them?
Thanks in advance.
David
sitemap menu
karan@dotnet
All-Star
26228 Points
4596 Posts
Re: Hide a certain child node only.
Jan 28, 2010 05:39 PM|LINK
Are you using any menu control like tree view etc to show your menu
Karan
~ Blog ~
Remember To Mark The Post(s) That Helped You As The ANSWER
DavidLee
Member
65 Points
45 Posts
Re: Hide a certain child node only.
Jan 28, 2010 05:49 PM|LINK
Hi,
On my master page I am using an asp menu control (vertically oriented) with a SiteMapDataSource.
The sitemap is below (I am trying to hide the nodes "contact-thanks.aspx" and "eval-thanks.aspx"
The menu control is below that (in case that helps)
<?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode url="~/Default.aspx" title="Home" description="Main Page"> <siteMapNode url="~/features/Default.aspx" title="Features" description="Features"> <siteMapNode url="~/features/comparison.aspx" title="Versions" description="Version Comparison" /> <siteMapNode url="~/features/snmp-views.aspx" title="SNMP Views" description="SNMP Views" /> <siteMapNode url="~/features/scalability.aspx" title="Scalability" description="Scalability" /> <siteMapNode url="~/features/system-requirements.aspx" title="System Req." description="SNMPc System Requirements" /> <siteMapNode url="~/features/trend-analysis-reporting.aspx" title="Trend Reporting" description="Trend Analysis Reporting" /> <siteMapNode url="~/features/programming.aspx" title="Programming" description="SNMPc Programming" /> <siteMapNode url="~/features/network-monitoring.aspx" title="Network Monitoring" description="Network Monitoring with SNMPc" /> <siteMapNode url="~/features/network-mapping.aspx" title="Network Mapping" description="Network Mapping with SNMPc" /> <siteMapNode url="~/features/reliability.aspx" title="Reliability" description="Reliability of SNMPc" /> <siteMapNode url="~/features/customization.aspx" title="Customization" description="Customization with SNMPc" /> <siteMapNode url="~/features/console-options.aspx" title="Console Options" description="SNMPc Console Options" /> <siteMapNode url="~/features/requirements.aspx" title="Requirements" description="SNMPc Requirements" /> </siteMapNode> <siteMapNode url="~/snmpc-online.aspx" title="SNMPc Online" description="SNMPc Online"> <siteMapNode url="~/snmpc-online/press-release.aspx" title="Press Release" description="SNMPc Online Press Release" /> </siteMapNode> <siteMapNode url="~/eval/default.aspx" title="Download" description="Download SNMPc Eval Version"> <siteMapNode url="~/eval/eval-thanks.aspx" title="Thanks" description="Thanks" /> </siteMapNode> <siteMapNode url="~/pricing.aspx" title="Pricing" description="SNMPc Pricing" /> <siteMapNode url="~/documentation.aspx" title="PDFs" description="SNMPc Documentation" /> <siteMapNode url="~/Contact.aspx" title="Contact" description="Contact Us"> <siteMapNode url="~/contact-thanks.aspx" title="Thanks" description="Thanks" /> </siteMapNode> <siteMapNode url="~/support.aspx" title="Support" description="SNMPC Support Information"> <siteMapNode url="~/support/faqs.aspx" title="FAQs" description="SNMPc Support FAQs" /> <siteMapNode url="~/support/knowledge-base.aspx" title="Knowledge Base" description="SNMPc Support Knowledge Base" /> <siteMapNode url="~/sitemap.aspx" title="Sitemap" description="Sitemap" /> </siteMapNode> </siteMapNode> </siteMap>The MENU
Thanks for your assistance. : )
karan@dotnet
All-Star
26228 Points
4596 Posts
Re: Hide a certain child node only.
Jan 28, 2010 05:59 PM|LINK
You can add a MenuItemDataBound for your menu.
And then in that event you can do something like this:
protected void Menu1_MenuItemDataBound(object sender, System.Web.UI.WebControls.MenuEventArgs e) { string text = e.Item.Text; if (text == "your item name to remove") { e.Item.Parent.ChildItems.Remove(e.Item); } }Try the above code and see if this helps.
Karan
~ Blog ~
Remember To Mark The Post(s) That Helped You As The ANSWER
mychucky
Contributor
4358 Points
3709 Posts
Re: Hide a certain child node only.
Feb 23, 2012 07:01 PM|LINK
Here's what I have:
protected void NavigationMenu_MenuItemDataBound(object sender, MenuEventArgs e) { Menu mnuNavMenu = (Menu)sender; SiteMapNode mapNode = (SiteMapNode)e.Item.DataItem; if (mapNode["hide"] != null && Convert.ToBoolean(mapNode["hide"])) { mnuNavMenu.Items.Remove(e.Item); } if (e.Item.Text == "Insert" || e.Item.Text == "Add" || e.Item.Text == "Edit") { //mnuNavMenu.Items.Remove(e.Item); e.Item.Parent.ChildItems.Remove(e.Item); } }I kept getting this error:
Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 26: { Line 27: //mnuNavMenu.Items.Remove(e.Item); Line 28: e.Item.Parent.ChildItems.Remove(e.Item); Line 29: } Line 30:mychucky
Contributor
4358 Points
3709 Posts
Re: Hide a certain child node only.
Feb 23, 2012 07:03 PM|LINK
Never mind, I got it working by using this: mnuNavMenu.Items.Remove(e.Item);