How can I enable/disable Menu Items at Runtime?

7 posts, 1 answers
  1. Ben Hayat
    Ben Hayat avatar
    892 posts
    Member since:
    May 2008

    Posted 16 Jan 2012 Link to this post

    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!
  2. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 16 Jan 2012 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Ben Hayat
    Ben Hayat avatar
    892 posts
    Member since:
    May 2008

    Posted 16 Jan 2012 Link to this post

    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!
  5. Kate
    Admin
    Kate avatar
    1898 posts

    Posted 19 Jan 2012 Link to this post

    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
  6. Ben Hayat
    Ben Hayat avatar
    892 posts
    Member since:
    May 2008

    Posted 19 Jan 2012 Link to this post

    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!
  7. Answer
    Kate
    Admin
    Kate avatar
    1898 posts

    Posted 21 Jan 2012 Link to this post

    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
  8. Ben Hayat
    Ben Hayat avatar
    892 posts
    Member since:
    May 2008

    Posted 21 Jan 2012 Link to this post

    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!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017