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

Discussion in 'ASP .Net' started by Karl, Nov 4, 2010.

  1. Karl

    Karl Guest

    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
     
    Karl, Nov 4, 2010
    #1
    1. Advertising

  2. Karl

    vani Guest

    "Karl" je napisao u poruci interesnoj
    grupi:...

    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.
     
    vani, Nov 5, 2010
    #2
    1. Advertising

  3. Karl

    Karl Guest

    On Nov 5, 8:05 am, "vani" <-com.hr> wrote:
    > "Karl"  je napisao u poruci interesnoj
    > grupi:....
    >
    > 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.
     
    Karl, Nov 11, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Randy Smith
    Replies:
    2
    Views:
    434
    Randy Smith
    Oct 21, 2006
  2. Benton
    Replies:
    0
    Views:
    398
    Benton
    Dec 9, 2006
  3. empire5
    Replies:
    1
    Views:
    590
    =?Utf-8?B?UmVuZ2E=?=
    Jan 11, 2007
  4. Larry Bud
    Replies:
    13
    Views:
    7,748
    Larry Bud
    Jan 7, 2008
  5. abrown
    Replies:
    1
    Views:
    256
    clickon
    Apr 28, 2006
Loading...

Share This Page