Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How do I work with ASP:Menu items in a masterpage loaded from sitemap?

Reply
Thread Tools

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

 
 
Karl
Guest
Posts: n/a
 
      11-04-2010
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
 
Reply With Quote
 
 
 
 
vani
Guest
Posts: n/a
 
      11-05-2010
"Karl" je napisao u poruci interesnoj
grupi:(E-Mail Removed)...

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.

 
Reply With Quote
 
 
 
 
Karl
Guest
Posts: n/a
 
      11-11-2010
On Nov 5, 8:05*am, "vani" <(E-Mail Removed)-com.hr> wrote:
> "Karl" *je napisao u poruci interesnoj
> grupi:(E-Mail Removed)....
>
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Masterpage change its masterpage mr t ASP .Net 0 08-29-2007 10:11 PM
MasterPages - take plain form, add MasterPage. MasterPage does NOT appear when run Randy Smith ASP .Net 9 04-14-2007 09:06 AM
MasterPage inheriting a MasterPage... is it possible? ThunderMusic ASP .Net 2 09-27-2006 07:57 PM
MasterPage -> Page -> MasterPage Code Access =?Utf-8?B?QWxleCBNYWdoZW4=?= ASP .Net 3 04-14-2006 12:34 PM



Advertisments