Dynamic Custom Layout Controls

Posted by Community Admin on 04-Aug-2018 14:48

Dynamic Custom Layout Controls

All Replies

Posted by Community Admin on 06-Sep-2012 00:00

I'm currently working on creating custom navigation menus partially based on the SiteMap from a particular starting page.  What I would like to do is have a custom layout container for each child item under the parent, particularly because there's no consistency in the design of the drop menus.  So the drop menus could be two, three, and eight columns each with differing content in those columns.

So my first botched implementation was to create a custom LayoutControl that had a repeater in it, read the child PageNodes, and render another LayoutControl within the repeater's item template.  Once the LayoutControl with the repeater is placed on the page, the HTML for the child LayoutControls are being rendered, but I don't have the ability to drag and drop into these child containers.

<%@ Control Language="C#" %>
 
<div id="Div1" runat="server" class="sf_cols">
    <div id="Div2" runat="server" class="sf_colsOut sf_1col_1_100">
        <div id="Div3" runat="server" class="sf_colsIn sf_1col_1in_100 myCustomCSSClass">
        </div>
    </div>
</div>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Web.UI;
 
namespace SitefinityWebApp.Controls.Navigation
    public partial class TopNavContentLayout : LayoutControl
    
        public string CustomTemplate = "~/controls/navigation/topnavcontentlayout.ascx";
 
        public override string Layout
        
            get
            
                return CustomTemplate;
            
        
 
        protected override void CreateChildControls()
        
            base.CreateChildControls();
        
    



<%@ Control Language="C#" %>
<asp:Repeater ID="rptControls" runat="server">
    <HeaderTemplate>
        <ul>
    </HeaderTemplate>
    <FooterTemplate>
        </ul>
    </FooterTemplate>
    <ItemTemplate>
        <li>
            <asp:HyperLink ID="hlPage" runat="server" />
            <asp:PlaceHolder ID="phControls" runat="server" />
        </li>
    </ItemTemplate>
</asp:Repeater>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Web.UI;
using Telerik.Sitefinity.Configuration;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Modules.Pages.Configuration;
using Telerik.Sitefinity.Pages.Model;
 
namespace SitefinityWebApp.Controls.Navigation
    public partial class TopNavigationLayout : LayoutControl
    
        #region [class variables]
 
        private PageManager _pgManager = null;
        private Guid _pageid = new Guid("5f9d97eb-b2d0-4487-99e5-d40009330739");
 
        #endregion
 
        #region [properties]
 
        protected PageManager PgManager
        
            get
            
                if (_pgManager == null)
                
                    _pgManager = PageManager.GetManager();
                
                return _pgManager;
            
        
 
        public string CustomTemplate = "~/controls/navigation/topnavigationlayout.ascx";
 
        public override string Layout
        
            get
            
                return CustomTemplate;
            
        
 
        #endregion
 
         
 
 
        protected override void CreateChildControls()
        
            base.CreateChildControls();
            BindRepeaterControls();
        
 
        private void BindRepeaterControls()
            var configManager = Config.GetManager();
            var config = configManager.GetSection<PagesConfig>();
            var id = config.HomePageId;
 
            PageNode node = PgManager.GetPageNode(id);
 
            if (this.Controls.Count > 0)
            
                Repeater rptControls = this.Controls[0].FindControl("rptControls") as Repeater;
                rptControls.ItemCreated += new RepeaterItemEventHandler(rptControls_ItemCreated);
                rptControls.DataSource = node.Nodes;
                rptControls.DataBind();
            
             
        
 
        private void rptControls_ItemCreated(object sender, RepeaterItemEventArgs e)
        
            PlaceHolder phControls = e.Item.FindControl("phControls") as PlaceHolder;
            HyperLink hlPage = e.Item.FindControl("hlPage") as HyperLink;
            PageNode item = e.Item.DataItem as PageNode;
 
            if (item != null && phControls != null && hlPage != null)
                TopNavContentLayout layout = new TopNavContentLayout();
                phControls.Controls.Add(layout);
 
                hlPage.Text = item.Title;
                hlPage.NavigateUrl = item.GetUrl();
            
        
 
    

This thread is closed