This is a migrated thread and some comments may be shown as answers.

How can I enable/disable Menu Items at Runtime?

6 Answers 140 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Ben Hayat
Top achievements
Rank 2
Ben Hayat asked on 16 Jan 2012, 10:00 AM
I would like to be able to access any menu item at runtime and based on certain logic be able to enable or disable or make it hide. What's the best way to identify each menu item at runtime? How do we give it an ID or some way to identify each one?

Reading form another post from three years ago, it was suggested to use Sitemap Datasource. Is there a better available now?
If we have to use the Sitemap Datasource (using XMLProvider the default), how can we use the icons that we have now at design time?

Thank you in advance!

6 Answers, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 16 Jan 2012, 11:39 AM
Hello Ben,

You can use any of the properties described in the Accessing Items help article in order to find a RadMenuItem at runtime.

Considering your other questions:
Reading form another post from three years ago, it was suggested to use Sitemap Datasource. Is there a better available now?If we have to use the Sitemap Datasource (using XMLProvider the default), how can we use the icons that we have now at design time?

Can you elaborate on your scenario - why you need to use Sitemap Datasource, what you need to do with the icons at design time?

Greetings,
Kate
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Ben Hayat
Top achievements
Rank 2
answered on 16 Jan 2012, 07:02 PM
Hi Kate;

Thank you for prompt response. The link you provided is a great value and I had missed it. I will look into it more today and If I have any questions, I'll follow up.

Can you elaborate on your scenario - why you need to use Sitemap Datasource, what you need to do with the icons at design time?

Sure! I'm working on an application that I have already created all my menus using Telerik Menu and each item has a nice Icon. I'm happy with this setup. However, when a user is NOT logged in (Not Authenticated), I need to either hide or disable some menu items and only show items for anonymous users. And when a user is Logged in, I need to do reverse, showing some items and hide others.
So, I was looking at the forum and saw this post where Paul from Telerik suggested to use SiteMapDataSource. Here But this involves in changing my menus and going a different direction. Also, when I was looking at the demos that menu Items come from DataBase or XML, none of them showed Icons. And that was my other question. "IF" I have to go through the SiteMapDataSource and connect it to Telerik Menu, how can I also display icon with each menu item, like I'm doing now?

So, what's your suggestion as far as direction and be able to control the menu items at runtime?

Thank you in advance!
0
Kate
Telerik team
answered on 19 Jan 2012, 01:03 PM
Hi Ben,

Thank you for clarifying. Here I have prepared a simple example how you can use SiteMapDataSource in a combination with RaMenu and images. Using the demonstrated approach you can handle your logic in the ItemDataBound event handler of the RadMenu.

Kind regards,
Kate
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Ben Hayat
Top achievements
Rank 2
answered on 19 Jan 2012, 03:06 PM
Hi kate;

Thank you for taking the time and preparing the sample. I'll go through it later on. But, do you think based on my need, do I even need to use SiteMapDataSource, or can I just do the filtering with the existing structure of the menu and it's items.

What's the general rule of just filtering Menu Items (let's say by text) v.s. going through the Sitemap and doing filtering on the datasource?

Thanks!
0
Accepted
Kate
Telerik team
answered on 21 Jan 2012, 12:39 PM
Hi Ben,

In general you can use either of the two approaches depending on your preferences. In the forum that you pointed out, Paul suggested using SiteMapDataSource due to its security trimming feature that will facilitate the "filtering" issue (you will not need to hardcode your logic as much as you would probably need when not using the SiteMapDataSource). However, if you are more comfortable implementing your own "filtering" of the menu items depending of the different users of your system you could skip the SiteMapDataSource binding and implement your preferred data binding.

All the best,
Kate
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Ben Hayat
Top achievements
Rank 2
answered on 21 Jan 2012, 06:06 PM
Thanks Kate;

Yes, for "this" case which there are multiple variable involved, besides security, it's actually easier to do it in the code than using SitMap. But your explanation made it easier for me to reach that decision.
Thank you!
Tags
Menu
Asked by
Ben Hayat
Top achievements
Rank 2
Answers by
Kate
Telerik team
Ben Hayat
Top achievements
Rank 2
Share this question
or