Removing Menu Items and Child Menu Items

Discussion in 'ASP .Net' started by Larry Bud, Jul 10, 2007.

  1. Larry Bud

    Larry Bud Guest

    Trying to conditionally remove menu items of the 2.0 .NET menu item
    control and I'm stumped.

    This removed a root level item:

    Menu1.Items.Remove(Menu1.FindItem("Administration"))

    But this does not remove it's child item

    Menu1.Items.Remove(Menu1.FindItem("Administration/Activities"))

    No errors are thrown, and FindItem *IS* finding Administration/
    Activities value path. I'm using the default value path separator of
    the forward slash, but the menu item still appears.

    What am I doing wrong? Thx.
    Larry Bud, Jul 10, 2007
    #1
    1. Advertising

  2. Larry Bud

    Larry Bud Guest

    On Jul 10, 2:32 pm, Larry Bud <> wrote:
    > Trying to conditionally remove menu items of the 2.0 .NET menu item
    > control and I'm stumped.
    >
    > This removed a root level item:
    >
    > Menu1.Items.Remove(Menu1.FindItem("Administration"))
    >
    > But this does not remove it's child item
    >
    > Menu1.Items.Remove(Menu1.FindItem("Administration/Activities"))
    >
    > No errors are thrown, and FindItem *IS* finding Administration/
    > Activities value path. I'm using the default value path separator of
    > the forward slash, but the menu item still appears.
    >
    > What am I doing wrong? Thx.


    Just a little more info:
    Menu1.FindItem("Administration/Activities").Enable=false

    DOES disable the menu item. So why can't I remove it?
    Larry Bud, Jul 10, 2007
    #2
    1. Advertising

  3. Hi Larry,

    > Trying to conditionally remove menu items of the 2.0 .NET menu item
    > control and I'm stumped.


    Why do you want to do this? I'd like to know, as there might be a smarter
    way than "items.remove".

    Jeppe Jespersen
    Denmark



    >
    > This removed a root level item:
    >
    > Menu1.Items.Remove(Menu1.FindItem("Administration"))
    >
    > But this does not remove it's child item
    >
    > Menu1.Items.Remove(Menu1.FindItem("Administration/Activities"))
    >
    > No errors are thrown, and FindItem *IS* finding Administration/
    > Activities value path. I'm using the default value path separator of
    > the forward slash, but the menu item still appears.
    >
    > What am I doing wrong? Thx.
    >
    Jeppe Jespersen, Jul 10, 2007
    #3
  4. Larry Bud

    Larry Bud Guest

    On Jul 10, 3:21 pm, "Jeppe Jespersen" <jdj at jdj dot dk> wrote:
    > Hi Larry,
    >
    > > Trying to conditionally remove menu items of the 2.0 .NET menu item
    > > control and I'm stumped.

    >
    > Why do you want to do this? I'd like to know, as there might be a smarter
    > way than "items.remove".


    To hide menu items based on a User's role.

    There's no "visible" property, and the Enable flag is just plain ugly.
    Larry Bud, Jul 10, 2007
    #4

  5. >> Why do you want to do this? I'd like to know, as there might be a smarter
    >> way than "items.remove".

    >
    > To hide menu items based on a User's role.


    Have you looked into the "security trimming" property on (i believe) the
    SiteMapProvider?
    Using this, you define in the web.config file what pages (and therefore
    menuitems) are visible/accessible to which users.

    It's pretty late here (in Euroland) $now, but I'll whip up an example
    tomorrow if you want?

    Jeppe Jespersen
    Denmark
    Jeppe Jespersen, Jul 10, 2007
    #5
  6. Hi, me again.

    Check out this MSDN article. Let me know if this is what you want.
    ....and if the article helped :)

    Jeppe
    Jeppe Jespersen, Jul 10, 2007
    #6
  7. Larry Bud

    sloan Guest

    Here is an interesting read:
    http://www.alexthissen.nl/blogs/mai...om-security-trimming-in-asp-net-sitemaps.aspx


    Or search for custom XmlSiteMapProvider variations.

    securityTrimmingEnabled is the other item of interest.


    The top URL is about rights (not roles), but it should lead you to the place
    you want to go.





    "Larry Bud" <> wrote in message
    news:...
    > Trying to conditionally remove menu items of the 2.0 .NET menu item
    > control and I'm stumped.
    >
    > This removed a root level item:
    >
    > Menu1.Items.Remove(Menu1.FindItem("Administration"))
    >
    > But this does not remove it's child item
    >
    > Menu1.Items.Remove(Menu1.FindItem("Administration/Activities"))
    >
    > No errors are thrown, and FindItem *IS* finding Administration/
    > Activities value path. I'm using the default value path separator of
    > the forward slash, but the menu item still appears.
    >
    > What am I doing wrong? Thx.
    >
    sloan, Jul 10, 2007
    #7
  8. Larry Bud

    Larry Bud Guest

    On Jul 10, 4:24 pm, "Jeppe Jespersen" <jdj at jdj dot dk> wrote:
    > Hi, me again.
    >
    > Check out this MSDN article. Let me know if this is what you want.
    > ...and if the article helped :)
    >
    > Jeppe


    Thanks, but you didn't post a link!
    Larry Bud, Jul 11, 2007
    #8
  9. Jeppe Jespersen, Jul 11, 2007
    #9
  10. Larry Bud

    Larry Bud Guest

    Larry Bud, Jul 11, 2007
    #10
  11. >
    > Thanks, and I may switch to this, but any idea on why I can't remove a
    > child item?
    >


    Hmm.... tried reproducing your problem, but wasn't able to.
    But have you tried something like:

    Menu1.FindItem("Fish").ChildItems.Clear()
    Menu1.Items.Remove(Menu1.FindItem("Fish"))

    -Jeppe
    Jeppe Jespersen, Jul 11, 2007
    #11
  12. Hi Larry,
    Dont know if you have a solution yet or not but I test the Text property
    of the menuitem to "" this had the effect of removing the menu entry. Hope
    this help.

    Cheers

    Vinnie

    "Larry Bud" wrote:

    > Trying to conditionally remove menu items of the 2.0 .NET menu item
    > control and I'm stumped.
    >
    > This removed a root level item:
    >
    > Menu1.Items.Remove(Menu1.FindItem("Administration"))
    >
    > But this does not remove it's child item
    >
    > Menu1.Items.Remove(Menu1.FindItem("Administration/Activities"))
    >
    > No errors are thrown, and FindItem *IS* finding Administration/
    > Activities value path. I'm using the default value path separator of
    > the forward slash, but the menu item still appears.
    >
    > What am I doing wrong? Thx.
    >
    >
    =?Utf-8?B?Vmlubmll?=, Sep 18, 2007
    #12
  13. Larry Bud

    hepek Guest

    try this:

    MenuItem menuItemAdmin = menuMain.FindItem("Administration");
    MenuItem menuItemActivities = menuMain.FindItem("Administration/Activities");
    menuItemAdmin.ChildItems.Remove(menuItemActivities );


    "Larry Bud" wrote:

    > Trying to conditionally remove menu items of the 2.0 .NET menu item
    > control and I'm stumped.
    >
    > This removed a root level item:
    >
    > Menu1.Items.Remove(Menu1.FindItem("Administration"))
    >
    > But this does not remove it's child item
    >
    > Menu1.Items.Remove(Menu1.FindItem("Administration/Activities"))
    >
    > No errors are thrown, and FindItem *IS* finding Administration/
    > Activities value path. I'm using the default value path separator of
    > the forward slash, but the menu item still appears.
    >
    > What am I doing wrong? Thx.
    >
    >
    hepek, Nov 29, 2007
    #13
  14. Larry Bud

    Larry Bud Guest

    > "Larry Bud" wrote:
    > > Trying to conditionally remove menu items of the 2.0 .NET menuitem
    > > control and I'm stumped.

    >
    > > This removed a root levelitem:

    >
    > > Menu1.Items.Remove(Menu1.FindItem("Administration"))

    >
    > > But this does notremoveit's childitem

    >
    > > Menu1.Items.Remove(Menu1.FindItem("Administration/Activities"))

    >
    > > No errors are thrown, and FindItem *IS* finding Administration/
    > > Activities value path. I'm using the default value path separator of
    > > the forward slash, but themenuitemstill appears.

    >
    > > What am I doing wrong? Thx.- Hide quoted text -



    On Nov 29 2007, 5:14 pm, hepek <>
    wrote:
    > try this:
    >
    > MenuItem menuItemAdmin = menuMain.FindItem("Administration");
    > MenuItem menuItemActivities = menuMain.FindItem("Administration/Activities");
    > menuItemAdmin.ChildItems.Remove(menuItemActivities );


    Thanks, this worked!
    Larry Bud, Jan 7, 2008
    #14
    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. Bryan
    Replies:
    1
    Views:
    761
    Steven Cheng[MSFT]
    Mar 1, 2006
  2. =?Utf-8?B?am9qb2Jhcg==?=
    Replies:
    0
    Views:
    548
    =?Utf-8?B?am9qb2Jhcg==?=
    Jul 13, 2006
  3. Jeff Rodriguez
    Replies:
    23
    Views:
    1,070
    David Schwartz
    Dec 9, 2003
  4. Chris  Chiasson
    Replies:
    6
    Views:
    596
    Richard Tobin
    Nov 14, 2006
  5. jobs
    Replies:
    1
    Views:
    777
    Larry Bud
    Oct 27, 2007
Loading...

Share This Page