LoadOnDemand when a menu item is clicked

4 posts, 0 answers
  1. ioannis
    ioannis avatar
    2 posts
    Member since:
    Jul 2010

    Posted 10 Feb 2011 Link to this post

    Hi all. I'm trying to use rad menu control with a web service loadondemand. I set property ClickToOpen="true" and the root menu opens on click. I want to do the same with the other menu items, to open on mouse click and not on mouse hover. Is this possible?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 10 Feb 2011 Link to this post

    Hello,


    I hope you can make use of client side api to change the behaviour of opening the menu item. Try canceling the OnClientItemOpening event based on condition, not when clicking teh item; which means the item opens only when clicking on it.

    The following links will be helpful in achieving this.
    OnClientItemOpening
    OnClientItemClicking


    Thanks,
    Princy.
  3. ioannis
    ioannis avatar
    2 posts
    Member since:
    Jul 2010

    Posted 10 Feb 2011 Link to this post

    Thanks for your reply Princy

    I follow your advice and i did the things below.

    1. Use the OnClientItemClicking="onClicking" to catch the clickevent. In clicking event i set a global variable (isclicked) equals to true. 
    2. Use the OnClientItemOpening="ItemOpening" event in order to open the menu only if isclicked variable is equals to true and then initialize the variable to false
    3. I already had the populating event OnClientItemPopulating="itemPopulating"  in order to pass parameters fron client side to server side.

    First time that i use the menu the event order is
    Clicking
    Opening
    Populating

    Unfortunatelly when i open the first submenu then event's order is different

    Scenario
    1. mouseover a sub menu
    2. Opening (caused from default behavior. In this event i cancel the opening)
    3. Clicking (I set variable isclicked to true)
    Opening will never be fired if i don't move the mouse over another menu item.

    So i guess the problem is that opening is fired before clicking and my submenu will never be populated from the web service.
    Is there any resolution for this? Can i fire the opening event into clicking?

    Thanks for your help

  4. Yana
    Admin
    Yana avatar
    5001 posts

    Posted 16 Feb 2011 Link to this post

    Hello ioannis,

    You can try it like this - subscribe to OnClientItemOpening and OnClientItemClicked event of the menu and add the following code snippets:

    <script type="text/javascript">
     
        function itemOpening(sender, args) {
            var item = args.get_item();
            if (item.get_level() > 0) {
                 
                if (item.get_attributes().getAttribute("isClicked") != "true") {
                    args.set_cancel(true);
                    item.get_attributes().setAttribute("isClilcked", "false");
                }
            }
        }
     
        function itemClicked(sender, args) {
            var item = args.get_item();
            if (item.get_level() > 0) {
                var item = args.get_item();
                item.get_attributes().setAttribute("isClilcked", "true");
                if(item.get_items().get_count() == 0)
                    item._loadChildrenFromWebService();
                item._doOpen(null);
            }
        }
    </script>


    All the best,
    Yana
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top