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

LoadOnDemand when a menu item is clicked

3 Answers 79 Views
Menu
This is a migrated thread and some comments may be shown as answers.
ioannis
Top achievements
Rank 1
ioannis asked on 10 Feb 2011, 10:45 AM
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?

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Feb 2011, 12:03 PM
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.
0
ioannis
Top achievements
Rank 1
answered on 10 Feb 2011, 02:16 PM
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

0
Yana
Telerik team
answered on 16 Feb 2011, 01:25 PM
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.
Tags
Menu
Asked by
ioannis
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
ioannis
Top achievements
Rank 1
Yana
Telerik team
Share this question
or