0

I have a radmenu (Telerik control) that is supposed to do two things when clicked: 1. open menu, 2. cancel postback.

Here is the menu:

<telerik:RadMenu ID="radMnu1" runat="server" ClickToOpen="true" OnClientItemClicked="MenuItemClicked" OnClientItemClicking="MenuItemClickingCancelPostback">
   <Items>...
   </Items>
</telerik:RadMenuItem>

And here are the JS methods:

function MenuItemClicked(sender, args) {
        var itemValue = args.get_item().get_value();

        var menu = $find("ctl00_radMnu1");
        var menuItem = menu.findItemByText(itemText);
        if (menuItem) menuItem.open();
        }
    }

    function MenuItemClickingCancelPostback(sender, args) {
        args.set_cancel(true); // Cancel the postback 
    }

The problem is that if I enable the OnItemClicking event, it executes it, cancels the postback then never enters the OnItemClicked (since the postback was cancelled). If I disable OnItemClicking, it fires OnItemClicked and opens the menu correctly, but then also does a postback.

How can I have both opening the menu and the postback cancel? Somehow I need to execute both events. I would cancel the postback on the OnItemClicked event, but the set_cancel() is not available in its args.

Thanks,

Amc_rtty
  • 3,662
  • 11
  • 48
  • 73
  • 1
    Why you don't use ItemClicking event for both actions? BTW, you don't need to call `$find` method in menu client event as you already have it from sender parameter – Yuriy Rozhovetskiy Oct 17 '12 at 19:18
  • And also, why you don't preventing postback with the `PostBack` menu items property? http://www.telerik.com/help/aspnet-ajax/p_telerik_web_ui_radmenuitem_postback.html – Yuriy Rozhovetskiy Oct 17 '12 at 19:25
  • your first comment worked, please write as answer so i can give credits – Amc_rtty Oct 21 '12 at 12:54

1 Answers1

0

Kindly wite the code using onitemclicking it will work for surely, like this

function MenuItemClickingCancelPostback(sender, args) {       
    // first open the menu then cancel the postback.
    var menu = $find("ctl00_radMnu1");
    var menuItem = menu.findItemByText(itemText);
    if (menuItem) menuItem.open();
    args.set_cancel(true); // Cancel the postback 
}
ahmed
  • 1