禁用顶级菜单项的 radmenu 单击事件

发布于 2024-12-26 05:45:45 字数 800 浏览 2 评论 0原文

在我的代码中,

    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
    {

    }

现在我想禁用单击“订单”而不是“采购商订单”,因为它是子项目。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

守护在此方 2025-01-02 05:45:45

首先,您需要将事件“OnClientItemClicking”添加到您的 RadMenu。像这样:

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

这是DisableRootClick javascript 函数的主体:

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
    } 

}

就在这里:)

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 :)

枯叶蝶 2025-01-02 05:45:45

有一个更简单的解决方案:

在服务器端:

RadMenuItem.PostBack = False

当然,您可以在控件中以声明的方式执行此操作

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

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>
愁以何悠 2025-01-02 05:45:45

这并不能解决您的问题,但我正在按照文档中此示例的思路实现一些内容: RadMenu 客户端事件文档 它可能会有所帮助。我需要禁用随机子项目和顶级项目。

如果未指定,navigateUrl 将始终是一个假锚点“#”。问题是它也对我想在服务器上处理的点击事件执行此操作,而且我的 rad 菜单混合了绑定到嵌套站点地图和通过后面的代码动态添加菜单项,所以现在我决定测试文本菜单项执行以下操作:

<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>

我确信有一个更优雅的解决方案,我至少可以将字符串移动到资源文件并引用它们,但这目前有效......

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文