How do I work with ASP:Menu items in a masterpage loaded from sitemap?

K

Karl

I've got an ASP:Menu on a MasterPage so that the menu shows on all
pages that use the masterpage

The menu is loaded from a site map and works well. Whenever I navigate
around using the menu, the correct class/style is applied to the
relevant menu item, showing which page I'm on.

However, I want to highlight a menu item when I am on a sub page of a
menu item, but cant seem to find how to reference the menu items in
code (C Sharp) so that at runtime the menu highlights as selected the
root page for the section of the site im in.

For instance, I have a menu that has just 8 root level options (but no
child menu items) so that these are shown across the top of my site
such as...

[Menu Item One | Menu Item Two | Menu Item Three | etc etc etc]

if I click Menu Item Three, then the correct page is shown and this
menu item is highlighted using CSS. but if this page has a sub page,
say a details page for an item selected on this page, called
"MenuItemThreeChildOne.aspx" I still want Menu Item Three on the menu
to be highlighted.

I am trying to do this in code, either on the masterpage or the
relevant child page, but cant seem to find the items in the menu no
matter when I look for them. I can use "FindControl" to get the menu,
but it always has 0 items.

Can anyone tell me how I'd find the item I want to set as selected
properly?

Thanks
 
V

vani

"Karl" je napisao u poruci interesnoj
grupi:9f0a323b-e47a-4c22-a3be-b08466c7aac1@u10g2000yqk.googlegroups.com...

I've got an ASP:Menu on a MasterPage so that the menu shows on all
pages that use the masterpage

The menu is loaded from a site map and works well. Whenever I navigate
around using the menu, the correct class/style is applied to the
relevant menu item, showing which page I'm on.

However, I want to highlight a menu item when I am on a sub page of a
menu item, but cant seem to find how to reference the menu items in
code (C Sharp) so that at runtime the menu highlights as selected the
root page for the section of the site im in.

For instance, I have a menu that has just 8 root level options (but no
child menu items) so that these are shown across the top of my site
such as...

[Menu Item One | Menu Item Two | Menu Item Three | etc etc etc]

if I click Menu Item Three, then the correct page is shown and this
menu item is highlighted using CSS. but if this page has a sub page,
say a details page for an item selected on this page, called
"MenuItemThreeChildOne.aspx" I still want Menu Item Three on the menu
to be highlighted.

I am trying to do this in code, either on the masterpage or the
relevant child page, but cant seem to find the items in the menu no
matter when I look for them. I can use "FindControl" to get the menu,
but it always has 0 items.

Can anyone tell me how I'd find the item I want to set as selected
properly?

Thanks


If it's an xml sitemap, you could try xpath-ing the xelement that holds the
current url and then xpath/loop your way to the topmost xelement(the one
whoose parent == null) that is your MenuItemThree or other.
That's one way to do it, but there are probably nicer ways to do the same.
 
K

Karl

"Karl"  je napisao u poruci interesnoj
grupi:9f0a323b-e47a-4c22-a3be-b08466c7a...@u10g2000yqk.googlegroups.com....

I've got an ASP:Menu on a MasterPage so that the menu shows on all
pages that use the masterpage

The menu is loaded from a site map and works well. Whenever I navigate
around using the menu, the correct class/style is applied to the
relevant menu item, showing which page  I'm on.

However, I want to highlight a menu item when I am on a sub page of a
menu item, but cant seem to find how to reference the menu items in
code (C Sharp) so that at runtime the menu highlights as selected the
root page for the section of the site im in.

For instance, I have a menu that has just 8 root level options (but no
child menu items) so that these are shown across the top of my site
such as...

[Menu Item One | Menu Item Two | Menu Item Three | etc etc etc]

if I click Menu Item Three, then the correct page is shown and this
menu item is highlighted using CSS. but if this page has a sub page,
say a details page for an item selected on this page, called
"MenuItemThreeChildOne.aspx" I still want Menu Item Three on the menu
to be highlighted.

I am trying to do this in code, either on the masterpage or the
relevant child page, but cant seem to find the items in the menu no
matter when I look for them. I can use "FindControl" to get the menu,
but it always has 0 items.

Can anyone tell me how I'd find the item I want to set as selected
properly?

Thanks

If it's an xml sitemap, you could try xpath-ing the xelement that holds the
current url and then xpath/loop your way to the topmost xelement(the one
whoose parent == null) that is your MenuItemThree or other.
That's one way to do it, but there are probably nicer ways to do the same..

Thanks Vani.

As the menu was hosted in a custom control, I've added a databound
event for it in the code behind that checks the filename of the
current page I'm on. I have a swicth statement (Select case in VB) in
the event and set the selected property of themenu item depending on
my file name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top