+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Setting active class

Setting active class

2 posts, 0 answered
  1. Daniel Plomp
    Daniel Plomp avatar
    112 posts
    Registered:
    14 Jun 2012
    01 Oct 2010
    Link to this post
    Hi all,

    I've adjusted the following method inside the SiteMenu.ascx.cs to set the <li> element of a menu item.

    public void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e)
        {
     
            CmsSiteMapNode node = e.Item.DataItem as CmsSiteMapNode;
            if (this.hideUrlForGroupPages)
            {
                if (node != null)
                {
                    // save the PageID in the attributes of the menu item
                    e.Item.Attributes.Add("PageID", node.Key);
     
                    if (node.PageType == CmsPageType.Group)
                    {
                        e.Item.NavigateUrl = "";
                    }
                }
            }
             
            CmsSiteMapNode currentNode = SiteMap.CurrentNode as CmsSiteMapNode;
            if (currentNode != null)
            {
                if (node.Key.Equals(currentNode.PageID.ToString()))
                    e.Item.OuterCssClass = "active";
                else if(node.ParentNode.Key.Equals(currentNode.PageID.ToString()))
                    e.Item.OuterCssClass = "active";
            }
        }

    How can I set the class of a parent item when I'm navigating to a sub item?

    Daniel
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    01 Oct 2010
    Link to this post
    Hello Daniel,

    You have a reference to the parent from e.Item.Parent and this should allow you to set the css. Another option is working with client side script where you can call get_parent

    Kind regards,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
2 posts, 0 answered