disable radmenu click event for top level menu items

5.8k Views Asked by At

in my code,

    MenuList = new Telerik.Web.UI.RadMenuItem();
    MenuChild1 = new Telerik.Web.UI.RadMenuItem();
    MenuList.Text = "Orders";
    MenuList.Value = "Orders";

    RadMenu_Control.Items.Add(MenuList);

    if (genRights.Find(delegate(UserRights u) { return u.RIGHT_NAME == "Group Master"; }) != null`enter code here`)
    {
        CategoryList = new Telerik.Web.UI.RadMenuItem();
        CategoryList.Text = "Purchase Order";
        CategoryList.Value = "order";
        MenuList.Items.Add(CategoryList);
        //MenuChild1 = new Telerik.Web.UI.RadMenuItem();
        //MenuChild1.Text = "PURCHASE ORDER";
        //MenuChild1.Value = "order";
        //MenuList.Items.Add(MenuChild1);
    }
    else
    {

    }

now in this i want to disable click on "Orders" not on "Purchaser order" because it is child item.

3

There are 3 best solutions below

0
On BEST ANSWER

First you need to add the event "OnClientItemClicking" to to your RadMenu. Like this:

<telerik:RadMenu ID="RadMenu1" runat="server" OnClientItemClicking="DisableRootClick">

And here is the body of the DisableRootClick javascript function:

function DisableRootClick (sender, args) {
    if (args.get_item().get_items().get_count() != 0 && args.get_item().get_level() == 0) {
            args.get_item().set_selected(false);
            args.get_item().set_focused(false);

            args.set_cancel(true); // Cancel the event
    } 

}

And here you go :)

0
On

This doesn't solve your problem but I'm implementing something along the lines of this example from the documentation: RadMenu Client Side Events Documentation and it may help. I need to disable random child and top items.

The navigateUrl will always be a fake anchor "#" if it's not specified. The problem is it also does this for click events that I want to handle on the server, plus my rad menu does a mixture of binding to nested sitemaps and dynamically adding menu items via the code behind so for now I decided to test for the text of the menu item doing the following:

<script type="text/javascript">

    function mainRadMenu_OnClientItemClicking( sender, eventArgs ) {

        var item = eventArgs.get_item();

        var itemText = item.get_text();

        var textOfMenuItemsToNotBeClicked = ['Tools', 'Links', 'No Links', 'Services', 'Summary Reports', '<%= GetOrganizationsAcronymMenuText %>'];

        var totalMenuItemsToNotBeClicked = textOfMenuItemsToNotBeClicked.length;

        while ( totalMenuItemsToNotBeClicked-- ) {

            if ( itemText.indexOf( textOfMenuItemsToNotBeClicked[totalMenuItemsToNotBeClicked] ) !== -1 ) {

                eventArgs.set_cancel( true );

            }
        }
    }
</script>


      <telerik:RadMenu ID="RadMenu1" runat="server" OnClientItemClicking="onClicking">
      ...
      </telerik:RadMenu>

I'm sure there's a more elegant solution, I could at least move the strings to a resource file and reference those, but this works for now...

0
On

There is a simpler solution:

On the server side:

RadMenuItem.PostBack = False

And, of course you can do it in a declarative manner in the control using

<telerik:RadMenu runat="server" ID="RadMenu1">
    <Items>
        <telerik:RadMenuItem runat="server" Text="RootMenu" PostBack="False" />
    </Items>
</telerik:RadMenu>