.Selected = false doesn't always work in MenuControl

Discussion in 'ASP .Net Web Controls' started by Wayne Erfling, Oct 15, 2006.

  1. I put in the code below to disable self links in a menu control in a "master" page.

    It works properly if the top-level menu item has no children, but both ..Selected = false and .NavigateUrl = null are ignored if the top-level menu item has nested (child) menu items. In other words, the menu item is active and still contains its previous value for ..NavigateUrl.

    This looks like a bug to me, and the documentation for .Selected suggests that it should be possible to disable a higher-level item while leaving the lower levels active.

    Is there something possibly about doing this in PreRender that is letting the menu control ignore the settings? Or could the child entries somehow be re-invigorating the top-level menu items?

    ---Wayne

    void Page_PreRender(object sender, EventArgs e)
    {
    // Disable self links (this page == NavigateUrl)

    bool bFirstTime = false;
    string [] allPaths;
    string [] PathParts;
    int i;

    MenuItemCollection items = idcMasterMenu.Items;

    PathParts = Request.Path.Split(new char[] {'/'}) ;

    allPaths = (string [])(Session["AllMenuUrls"]);


    if (allPaths == null)
    {
    bFirstTime = true;
    allPaths = new string[items.Count];
    }


    for (i=0; i < items.Count; i++)
    {
    if (bFirstTime)
    allPaths = items.NavigateUrl; // be able to restore if nulled out


    if (items.NavigateUrl.ToLower().IndexOf(PathParts[PathParts.Length-1].ToLower()) > -1)
    {
    items.Selectable = false;
    items.NavigateUrl = null;
    }
    else
    {
    items.Selectable = true;
    items.NavigateUrl = allPaths; // restore from saved values
    }
    }
    if (bFirstTime)
    Session["AllMenuUrls"] = allPaths;

    } // PreRender
     
    Wayne Erfling, Oct 15, 2006
    #1
    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. Wayne Erfling
    Replies:
    0
    Views:
    461
    Wayne Erfling
    Oct 13, 2006
  2. Iain
    Replies:
    3
    Views:
    938
  3. DC
    Replies:
    1
    Views:
    3,197
  4. Mark B
    Replies:
    0
    Views:
    519
    Mark B
    Sep 30, 2008
  5. Mark B

    Alternative to asp:MenuControl?

    Mark B, Feb 7, 2009, in forum: ASP .Net
    Replies:
    11
    Views:
    1,767
    Juan T. Llibre
    Feb 24, 2009
Loading...

Share This Page