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

Forums / Developing with Sitefinity / SitePanelBar Expand mode

SitePanelBar Expand mode

12 posts, 0 answered
  1. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    23 Sep 2009
    Link to this post
    Hi,

    I have the sitepanelbar format as given below
    -- Page1
        --level2
        --level2
    --Page2
    --Page3

    What I need is, when I am in Page2 and clicked on Page1 then, I want to see the subpages in Page1 as expanded without navigating to that Page1. Page1 is of PageGroup type.

    Any help is greatly appreciable...


    -Thanks
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    23 Sep 2009
    Link to this post
    Hello Dinesh,

    Please add the logic below to RadPanelBar's  OnClientItemClicking event.

    <script type="text/javascript">  
    function OnClientItemClicking(sender, args)  
    {  
       var item = args.get_item();  
       if (item.get_level()==0)  
       {  
           args.set_cancel(true);  
           item.set_expanded(!item.get_expanded());  
       }  
       else  
       {  
          args.set_cancel(false);  
       }  
    }  
    </script>  

    I hope this helps.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    23 Sep 2009
    Link to this post
    Hello Ivan,

    Thanks for the code. It is not allowing for the other pages to navigate. I need to block the postback for only the item that is having subpages i.e for Page1 only. Page2 and Page3 don't have any subpages and they should be navigable.

    -Thanks
  4. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    23 Sep 2009
    Link to this post
    Modifying the above code does the trick
    function OnClientItemClicking(sender, args)    
    {  
        var item = args.get_item();  
        var items = item.get_items();  
        var count = items.get_count();  
          
        if (count > 0) {  
            if (item.get_level() == 0) {  
                args.set_cancel(true);  
                item.set_expanded(!item.get_expanded());  
            }  
            else {  
                args.set_cancel(false);  
            }  
        }   
        else  
            args.set_cancel(false);  
    }  

    Thanks Ivan it helped. Thank you very much for the reply

  5. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    24 Sep 2009
    Link to this post
    I would like to restrict this functionality only for page groups. So, how can I check the page group property in javascript?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    24 Sep 2009
    Link to this post
    Hi Dinesh,

    It is not possible to check whether an node is Group or not using js. You should do it on the server. Sample code:

                CmsSiteMapNode node = e.Item.DataItem as CmsSiteMapNode; 
                if (node != null && node.PageType == CmsPageType.Group) 
                { 
                     // do something here 
                } 

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    24 Sep 2009
    Link to this post
    Hi Ivan

    I added onItemdatabound event for radpanelbar
    protected void radPanelBar1_OnItemDataBound(object sender, RadPanelBarEventArgs e)  
        {  
            CmsSiteMapNode node = e.Item.DataItem as CmsSiteMapNode;  
              
            if (node != null && node.PageType == CmsPageType.Group)  
            {  
                item.Attributes.Add("OnClientItemClicking", "OnClientItemClickingFunction");  
                radPanelBar1.Attributes.Add("OnClientItemClicking", "OnClientItemClickingFunction");  
     
            }  
        } 
     
    But, I was surprised that the 'node' is showing null everytime even 'e.Item.DataItem' is not null. Am I missing anything?



  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    24 Sep 2009
    Link to this post
    Hi Dinesh,

    Use  RadPanelbar1.ItemDataBound or RadPanelbar1.DataBound events. You can gather more information about the server side events from RadPanelBar developer manual. 

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    24 Sep 2009
    Link to this post
    Can't we cast SiteMapNode to CmsSiteMapNode?
    I am using custom sitepanel bar and I am not giving any datasource and binding the nodes in c#. There I am casting those nodes as SiteMapNode. So now I tried to cast it to CmsSiteMapNode as SiteMapNode doesn't have PageType property.
    But, when I tried to cast the node it is giving null value even if SiteMapNode is not null. So, Can't we cast SiteMapNode to CmsSiteMapNode?
  10. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    01 Jun 2017
    24 Sep 2009
    Link to this post
    Hi Dinesh,

    I tried using the code shown below and it works.

    protected void Page_Load(object sender, EventArgs e) 
        { 
            var node = (CmsSiteMapNode)SiteMap.Provider.RootNode.ChildNodes[0]; 
     
            Response.Write("Title:" + node.Title + "; Url:" + node.Url + "; PageType:" + node.PageType.ToString()); 
        } 

     Can you please send us the code that you are trying?

    Sincerely yours,
    Nikolai
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  11. Dinesh
    Dinesh avatar
    46 posts
    Registered:
    03 Aug 2009
    24 Sep 2009
    Link to this post
    I am binding the nodes in the following way

    List<SiteNode> GetNodes(SiteMapNodeCollection nodeCollection)  
        {  
            List<SiteNode> lstSiteNodes = new List<SiteNode>();  
            SiteNode siteNode;  
            SiteNode siteSubNode;  
            SiteNode siteSecondSubNode;  
     
            foreach (SiteMapNode node in nodeCollection)  
            {  
                if (node.ChildNodes.Count >= 0 && !node.Title.Contains("Home"))  
                {  
                    siteNode = new SiteNode();  
                    siteNode.Url = node.Url;  
                    siteNode.Title = node.Title;  
                    siteNode.Nodes = new List<SiteNode>();  
     
                    //CmsSiteMapNode nodeItem = node as CmsSiteMapNode;  
                      
                    //if (nodeItem.PageType == CmsPageType.Group)  
                    //{  
                    //    radPanelBar1.Attributes.Add("OnClientItemClicking", "OnClientItemClicking");  
                    //}  
                }  
            }  
           
      }  
     

    Commented are the lines where I am unable to cast into CmsSiteMapNode even the node value is not null. It is not giving any exception but after casting the nodeItem is showing as null.







  12. Nikolai
    Nikolai avatar
    216 posts
    Registered:
    01 Jun 2017
    25 Sep 2009
    Link to this post
    Hello Dinesh,

    As far I see from your code this will not work because you cannot retrieve Sitefinity's page via the SiteMap class as they are contained inside the DB not as physical files.
    I suggest you use approach like this to get the page type:
    protected void Page_Load(object sender, EventArgs e) 
        {         
            var provider = SiteMap.Providers["CmsSiteMapProvider"]; 
            var rootNode = (CmsSiteMapRoot)provider.RootNode;         
             
            foreach(ICmsPage page in rootNode.RootPage.Pages)    
            { 
                Response.Write("Title:" + page.Title + "; Url:" + page.DefaultUrl.Url + "; PageType:" + page.PageType.ToString() + "; PageType:" + page.PageType+"\r\n"); 
            } 
        } 


    Kind regards,
    Nikolai
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
12 posts, 0 answered