Removing Menu Items and Child Menu Items

Removing Menu Items and Child Menu Items

am 10.07.2007 20:32:18 von Larry Bud

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.

Re: Removing Menu Items and Child Menu Items

am 10.07.2007 21:19:29 von Larry Bud

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?

Re: Removing Menu Items and Child Menu Items

am 10.07.2007 21:21:35 von Jeppe Dige Jespersen

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.
>

Re: Removing Menu Items and Child Menu Items

am 10.07.2007 21:41:11 von Larry Bud

On Jul 10, 3:21 pm, "Jeppe Jespersen" 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.

Re: Removing Menu Items and Child Menu Items

am 10.07.2007 22:11:15 von Jeppe Dige Jespersen

>> 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

Re: Removing Menu Items and Child Menu Items

am 10.07.2007 22:24:58 von Jeppe Dige Jespersen

Hi, me again.

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

Jeppe

Re: Removing Menu Items and Child Menu Items

am 10.07.2007 22:37:09 von sloan

Here is an interesting read:
http://www.alexthissen.nl/blogs/main/archive/2006/08/23/cust 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:1184092338.864285.283100@q75g2000hsh.googlegroups.com.. .
> 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.
>

Re: Removing Menu Items and Child Menu Items

am 11.07.2007 03:19:32 von Larry Bud

On Jul 10, 4:24 pm, "Jeppe Jespersen" 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!

Re: Removing Menu Items and Child Menu Items

am 11.07.2007 05:43:45 von Jeppe Dige Jespersen

>
> Thanks, but you didn't post a link!
>

Oops :-)
Here you go....
http://msdn2.microsoft.com/en-us/library/ms178428(vs.80).asp x

Jeppe

Re: Removing Menu Items and Child Menu Items

am 11.07.2007 14:15:36 von Larry Bud

On Jul 10, 11:43 pm, "Jeppe Jespersen" wrote:
> > Thanks, but you didn't post a link!
>
> Oops :-)
> Here you go....http://msdn2.microsoft.com/en-us/library/ms178428(vs.8 0).aspx
>
> Jeppe

Thanks, and I may switch to this, but any idea on why I can't remove a
child item?

Re: Removing Menu Items and Child Menu Items

am 11.07.2007 21:00:16 von Jeppe Dige Jespersen

>
> 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

RE: Removing Menu Items and Child Menu Items

am 18.09.2007 16:58:03 von Vinnie

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.
>
>

RE: Removing Menu Items and Child Menu Items

am 29.11.2007 23:14:02 von hepek

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.
>
>

Re: Removing Menu Items and Child Menu Items

am 07.01.2008 15:12:33 von Larry Bud

> "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=A0pm, hepek
wrote:
> try this:
>
> MenuItem menuItemAdmin =3D menuMain.FindItem("Administration");
> MenuItem menuItemActivities =3D menuMain.FindItem("Administration/Activiti=
es");
> menuItemAdmin.ChildItems.Remove(menuItemActivities );

Thanks, this worked!