Home / Community & Support / Knowledge Base / RadControls for ASP.NET AJAX / Menu / Show Path with client-side implementation

Show Path with client-side implementation

Article Info

Rating: Not rated


Article information

Article relates to

 RadMenu for ASP.NET AJAX Q1 2011 or later

Created by

 Katerina, Telerik

Last modified

 November 3, 2011

Last modified by

  Katerina, Telerik


HOW-TO:
Show the path to a clicked item of the RadMenu control using client-side

SOLUTION:
Using javascript you will need to set the rmFocused css class that will highlight the path to the currently clicked item of the menu.  Of course you will also need to set different URL-s to the RadMenuItems as demonstrated in the markup below. 

<script type="text/javascript">
        function OnClientLoad(sender) {
            var menu = sender;
            for (var i = 0; i < menu.get_allItems().length; i++) {
                var item = menu.get_allItems()[i];
                var currentUrl = window.location.toString();
                if (currentUrl.match(item.get_navigateUrl()) != null) {
                    item.select();
                    highlightPath(item);
                    break;
                }
            }
        }
 
        function highlightPath(item) {
            item.set_cssClass("rmFocused");
     //item.get_parent() is RadMenuItem, not RadMenu       
            if (item.get_parent() != item.get_menu())
                highlightPath(item.get_parent());          
        }
    </script>

<telerik:RadMenu ID="RadMenu1" runat="server" OnClientLoad="OnClientLoad" >
        <Items>
            <telerik:RadMenuItem runat="server" NavigateUrl="PageA.aspx" Text="Root Item A">
                <Items>
                    <telerik:RadMenuItem Text="Item1" NavigateUrl="PageA1.aspx">
                        <Items>
                            <telerik:RadMenuItem Text="Item11" NavigateUrl="PageA11.aspx" />
                            <telerik:RadMenuItem Text="Item12" NavigateUrl="PageA12.aspx" />
                        </Items>
                    </telerik:RadMenuItem>
                    <telerik:RadMenuItem Text="Item2" NavigateUrl="PageA2.aspx">
                    </telerik:RadMenuItem>
                </Items>
            </telerik:RadMenuItem>
            <telerik:RadMenuItem runat="server" NavigateUrl="PageB.aspx" Text="Root Item B">
            </telerik:RadMenuItem>
            <telerik:RadMenuItem runat="server" NavigateUrl="PageC.aspx" Text="Root Item C">
            </telerik:RadMenuItem>
        </Items>
    </telerik:RadMenu>

Comments

There are no comments yet.
If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.