More in this section

Forums / Developing with Sitefinity / Layout Custom Control - receiving error w/ multiple content blocks

Layout Custom Control - receiving error w/ multiple content blocks

2 posts, 0 answered
  1. Steve
    Steve avatar
    16 posts
    Registered:
    14 Jul 2010
    27 Oct 2011
    Link to this post
    I'm building a custom layout control and have it working just fine except i'm getting an error when I drop more than 1 content block into a placeholder.

    I suspect I need to override something in my CustomControl to assign something a unique name, but not sure what. 

    My Custom Control code:
    01.public class WebCustomControl1 : LayoutControl
    02.    {
    03.        /// <summary>
    04.        /// CustomTemplate lets you supply a template.ascx file to render the layout.
    05.        /// </summary>
    06.        public string CustomTemplate = "SitefinityWebApp.LayoutControls.Layout1.ascx";
    07. 
    08.        public override string Layout
    09.        {
    10.            get { return this.CustomTemplate; }
    11.            set { CustomTemplate = value; }
    12.        }
    13. 
    14.        public override string AssemblyInfo
    15.        {
    16.            get { return GetType().ToString(); }
    17.            set { base.AssemblyInfo = value; }
    18.        }
    19. 
    20.        protected override void CreateChildControls()
    21.        {
    22.            base.CreateChildControls();
    23.        }
    24.    }

    My ASCX file:
    <%@ Control Language="C#" %>
     
    <div class="trio first">
        <div id="div1" runat="server" class="sf_cols">
            <div id="div2" runat="server" class="sf_colsOut">
                <div id="div3" runat="server" class="sf_colsIn">
                </div>
            </div>
        </div>
    </div>
    <div class="trio">
        <div id="Div4" runat="server" class="sf_cols">
            <div id="div5" runat="server" class="sf_colsOut">
                <div id="div6" runat="server" class="sf_colsIn">
                </div>
            </div>
        </div>
    </div>
    <div class="trio last">
    <div id="Div7" runat="server" class="sf_cols">
            <div id="div8" runat="server" class="sf_colsOut">
                <div id="div9" runat="server" class="sf_colsIn">
                </div>
            </div>
        </div>
    </div>


    Error is:

    Server Error in '/' Application.

    An item with the same key has already been added.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.ArgumentException: An item with the same key has already been added.

    Source Error: 

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace: 

    [ArgumentException: An item with the same key has already been added.]
       System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +52
       System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +9375087
       System.Collections.ObjectModel.KeyedCollection`2.AddKey(TKey key, TItem item) +70
       System.Collections.ObjectModel.KeyedCollection`2.InsertItem(Int32 index, TItem item) +38
       System.Collections.ObjectModel.Collection`1.Add(T item) +98
       Telerik.Sitefinity.Web.UI.PlaceHoldersCollection.AddRange(IEnumerable`1 controls) +77
       Telerik.Sitefinity.Modules.Pages.PageHelper.CreateChildControls(IList`1 controls, Page page, Boolean ignoreCultures) +957
       Telerik.Sitefinity.Modules.Pages.DraftProxyBase.CreateChildControls(Page page) +327
       Telerik.Sitefinity.Modules.Pages.TemplateEditorRouteHandler.ApplyLayoutsAndControls(Page page, RequestContext requestContext) +226
       Telerik.Sitefinity.Web.RouteHandler.InitializeContent(Page handler, RequestContext requestContext) +53
       Telerik.Sitefinity.Web.RouteHandler.Handler_Load(Object sender, EventArgs e) +214
       System.Web.UI.Control.OnLoad(EventArgs e) +91
       System.Web.UI.Control.LoadRecursive() +74
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
    


    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.468

  2. Steve
    Steve avatar
    16 posts
    Registered:
    14 Jul 2010
    28 Oct 2011
    Link to this post
    A rebuild of the project and restart of Sitefinity resolved this.
2 posts, 0 answered