I am trying to hide certain items from my menu and I getting an error "Unable to cast object of type 'System.EventArgs' to type 'System.Web.UI.WebControls.MenuEventArgs'."
Any ideas?
Protected Sub MainMenu_DataBinding(sender As Object, e As MenuEventArgs) Handles MainMenu.DataBinding
If user = "someone" Then
'Check for Roles or users here
If e.Item.Text = "Projects" OrElse e.Item.Text = "administration" Then
e.Item.Parent.ChildItems.Remove(e.Item)
End If
End If
End Sub
Use the MenuItemDataBound event instead. I think it will work
Protected Sub MainMenu_MenuItemDataBound(sender As Object, e As System.Web.UI.WebControls.MenuEventArgs) Handles MainMenu.MenuItemDataBound
If user = "someone" Then
'Check for Roles or users here
If e.Item.Text = "Projects" OrElse e.Item.Text = "administration" Then
e.Item.Parent.ChildItems.Remove(e.Item)
End If
End If
End Sub
Remember to click Mark As Answer when you get a reply which answers your question.
My Blog: ASP.NET Stuff
Marked as answer by MKozlowski on May 16, 2012 02:00 PM
That works for first tab "projects" but it doesnt see the other tab called adminstration? Is there a way to hide the second tab? I have 2 main tabs. Thanks!
MKozlowski
Member
500 Points
573 Posts
Unable to cast object of type 'System.EventArgs'
May 16, 2012 12:17 PM|LINK
Hi,
I am trying to hide certain items from my menu and I getting an error "Unable to cast object of type 'System.EventArgs' to type 'System.Web.UI.WebControls.MenuEventArgs'."
Any ideas?
Protected Sub MainMenu_DataBinding(sender As Object, e As MenuEventArgs) Handles MainMenu.DataBinding If user = "someone" Then 'Check for Roles or users here If e.Item.Text = "Projects" OrElse e.Item.Text = "administration" Then e.Item.Parent.ChildItems.Remove(e.Item) End If End If End Subrobwscott
Star
8079 Points
1491 Posts
Re: Unable to cast object of type 'System.EventArgs'
May 16, 2012 12:33 PM|LINK
you need to parse
protected void MainMenu_MenuItemDataBound(object sender, MenuEventArgs e) { MenuItem menu = ((MenuItem)e.Item); if (menu.Text == "Projects" || menu.Text == "administration") { MainMenu.Items.Remove(menu); } }Mark Answered if it helps - Good luck!
Cheers!
Design And Align
- Rob
Kulrom
Contributor
4832 Points
892 Posts
Re: Unable to cast object of type 'System.EventArgs'
May 16, 2012 12:33 PM|LINK
Use the MenuItemDataBound event instead. I think it will work
Protected Sub MainMenu_MenuItemDataBound(sender As Object, e As System.Web.UI.WebControls.MenuEventArgs) Handles MainMenu.MenuItemDataBound If user = "someone" Then 'Check for Roles or users here If e.Item.Text = "Projects" OrElse e.Item.Text = "administration" Then e.Item.Parent.ChildItems.Remove(e.Item) End If End If End SubMy Blog: ASP.NET Stuff
MKozlowski
Member
500 Points
573 Posts
Re: Unable to cast object of type 'System.EventArgs'
May 16, 2012 12:50 PM|LINK
Ok that works for the sub menus. If I want to hide a whole tab can this be done also?. The tab text is Administration.
Kulrom
Contributor
4832 Points
892 Posts
Re: Unable to cast object of type 'System.EventArgs'
May 16, 2012 03:01 PM|LINK
I am not sure i understand entirely but if you want to hide the administration then just use remove method again.
My Blog: ASP.NET Stuff
MKozlowski
Member
500 Points
573 Posts
Re: Unable to cast object of type 'System.EventArgs'
May 16, 2012 03:41 PM|LINK
That works for first tab "projects" but it doesnt see the other tab called adminstration? Is there a way to hide the second tab? I have 2 main tabs. Thanks!
MKozlowski
Member
500 Points
573 Posts
Re: Unable to cast object of type 'System.EventArgs'
May 16, 2012 03:47 PM|LINK
nm got it working thanks for all your help.
If e.Item.Text = "Projects" OrElse e.Item.Text = "Administration" Then MainMenu.Items.Remove(e.Item) End If