Welcome Guest Search | Active Topics | Sign In | Register

Referencing specific menu items from Master Pages Options
Simon
Posted: Tuesday, December 9, 2008 10:14:18 AM
Rank: Newbie
Groups: Member

Joined: 12/9/2008
Posts: 3
Using ASP.Net 2.0, I want to reference a specific menu item from the Master Page code behind. If a user is not authenticated or in the right role, I want to make certain menu items invisible. I thought that I'd do this

EO.Web.NavigationItem.ItemID("mnuOffLimits").Visible = false

However this and other permutations I've tried don't work. Please walk me through controlling the visibility of menu items based on user authentication and roles.
Code: Visual Basic.NET
eo_support
Posted: Tuesday, December 9, 2008 12:48:57 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

The easiest way is to set the MenuItem's AllowRoles property:

http://www.essentialobjects.com/ViewDoc.aspx?t=EO.Web.NavigationItem.AllowRoles.html

You can also find the corresponding menu item and set its Visible property. However your code is wrong. ItemID is an instance property and it returns the ID of the item, where you assumed it would find a matching item with the given ID value, which it does not do. The following function might be the closest to what you are looking for:

http://www.essentialobjects.com/ViewDoc.aspx?t=EO.Web.BaseNavigator.FindItem.html

As a general guide line, you should always follow the documentation for each property/methods. Each property/method should do exactly what the documentation says it to do and not anything else. So you should always try to seek confirmation from the documentation first when you are not sure about something.

Thanks
Simon
Posted: Tuesday, December 9, 2008 2:36:23 PM
Rank: Newbie
Groups: Member

Joined: 12/9/2008
Posts: 3
Ok, so I used this code

Code: Visual Basic.NET
Dim valuePath As String = "mnuNavigation/mnuNewsletters/mnuArchives"
Dim item As EO.Web.MenuItem = CType(mnuNavigation.FindItem(valuePath), EO.Web.MenuItem)
item.Visible = false


But it does not work. Apparently, item is not an object. Please advise.
eo_support
Posted: Tuesday, December 9, 2008 2:44:57 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Your code looks correct. If FindItem does not return you a valid item, it only means the path you give to it is wrong. So I would check the ItemID property of each MenuItem and see if they are correctly set.
Simon
Posted: Tuesday, December 9, 2008 2:53:18 PM
Rank: Newbie
Groups: Member

Joined: 12/9/2008
Posts: 3
This is the error message

Object reference not set to an instance of an object.

So then I tried Dim item as new EO.Web.MenuItem = CType(mnuNavigation.FindItem(valuePath), EO.Web.MenuItem)

No luck there either.
eo_support
Posted: Tuesday, December 9, 2008 3:09:43 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Simon wrote:
Object reference not set to an instance of an object.


We have already pointed out the reason in our previous reply. If you still have trouble with it, you may wish to ask someone around you for help.

It is important for you to understand that while our support won't mind to point you to the right direction, we do not code for you, nor debug your code. So you will need to solve most of the coding issues by yourself.

If you suspect there is a problem with our product, please create a test page with detailed steps to reproduce the problem. We will be happy to take a look once we have that.

You can review our official support policy here:

http://www.essentialobjects.com/Forum/Default.aspx?g=posts&t=1368

Thanks


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.