telerik radmenu cancel postback after action

1.9k Views Asked by At

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,

1

There are 1 best solutions below

0
On

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 
}