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

Forums / Developing with Sitefinity / Latest event - CreateSingleContent throwing error

Latest event - CreateSingleContent throwing error

4 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    02 Sep 2010
    Link to this post
    Hi,

    I've copied a "Latest news" control that I developed so that i could display a "Latest Event"

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.News;
    using Telerik.Events;
    using Telerik.Web;
    using Telerik.Cms.Engine.ContentViewFiltering;
    using System.Web.UI.WebControls;
    using System.ComponentModel;
     
    /// <summary>
    /// Summary description for LatestNewsControl
    /// </summary>
    public class LatestEventsControl : Telerik.Events.WebControls.EventsView {
     
        public LatestEventsControl() {
            //
            // TODO: Add constructor logic here
            //
        }
     
        #region Properties
     
        //public override string ItemListTemplatePath {
        //    get { return "~/Sitefinity/ControlTemplates/News/ListPageMaster.ascx"; }
        //}
     
        public override string SingleItemTemplatePath {
            get { return "~/lib/controls/events/frontend/LatestEventControl.ascx"; }
        }
     
        #endregion
     
        protected override void CreateChildControls()
        {
            // instance of EventsManager
            var oEventsMgr = new EventsManager("Events");
     
            // get all items by Publication date and get the first content item
            var listofAll = oEventsMgr.Content.GetContent("Publication_Date DESC");
            var oContent = listofAll[0] as Telerik.Cms.Engine.IContent;
              
            //set the item ID
            if (Context.Items.Contains(this.Manager.Provider.ContentItemKey))
     
                itemId = (Guid)((IUrlRewriteData)Context.Items[Manager.Provider.ContentItemKey]).Data;
     
            else if (!String.IsNullOrEmpty(Context.Request[ContentItemKey]))
     
                itemId = new Guid(Context.Request[ContentItemKey]);
     
            else
            {
                itemId = oContent.ID;
            }
        
            if (this.itemId != Guid.Empty && SingleModeSupported)
            {
                ContentFilterBuilder filterBuilder = new ContentFilterBuilder(this);
                filterBuilder.AddFilter(new ContentFilterStatement("ID", itemId.ToString(), ContentFilter.Condition.Equal));
                this.CreateSingleContent();
     
                try {
     
                    Controls.Add(SingleContainer);
     
                } catch (Exception e) { }
            }
     
            base.CreateChildControls();
     
        }
     
    }

    The line of code this.CreateSingleContent is throwing an "Object reference not set to an instance of an object", however this works perfectly when dealing with single news items.

    Does anyone know why there is a difference?

    Thanks in advance
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Sep 2010
    Link to this post
    Hello Alastair,

    CreateSingleContent - creates child controls for displaying single content item. The method is called only when behavior mode is Details.

    Best wishes,
    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
  3. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    02 Sep 2010
    Link to this post
    Hi Ivan,

    I have manually set the BehaviourMode to Detail. This exact code works perfectly for the latest news article, the only line I have changed is:

    // instance of EventsManager
    var oEventsMgr = new EventsManager("Events");

    The stack is:

    [NullReferenceException: Object reference not set to an instance of an object.]
       Telerik.Events.WebControls.EventsView.TryParseGeomappingData(IContent cnt) +16
       Telerik.Events.WebControls.EventsView.SetItemMetadata(Control itemContainer, IContent contentItem) +82
       Telerik.Cms.Engine.WebControls.ContentView.CreateSingleContent() +2173
       Telerik.Events.WebControls.EventsView.CreateSingleContent() +4
       LatestEventsControl.CreateChildControls() in d:\phoenix\www\App_Code\LatestEventsControl.cs:69
       System.Web.UI.Control.EnsureChildControls() +87
       System.Web.UI.Control.PreRenderRecursiveInternal() +44
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Control.PreRenderRecursiveInternal() +171
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842

    Does this give any more insight?

    Thanks
    higgsy
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Sep 2010
    Link to this post
    Hello Alastair,

    Modify CreateChildControls  as shown below

    protected override void CreateChildControls()
       {
     
           base.CreateChildControls();
           base.ListContainer.Visible = false;
               eventsManager = new EventsManager(base.ProviderName);
              var oContent = (IContent)this.CreateDataSource()[0];
     
           if (Context.Items.Contains(this.Manager.Provider.ContentItemKey))
               itemId = (Guid)((IUrlRewriteData)Context.Items[Manager.Provider.ContentItemKey]).Data;
           else if (!String.IsNullOrEmpty(Context.Request[ContentItemKey]))
               itemId = new Guid(Context.Request[ContentItemKey]);
     
           else
           {
               itemId = oContent.ID;
           }
     
           if (this.itemId != Guid.Empty && SingleModeSupported)
           {
               ContentFilterBuilder filterBuilder = new ContentFilterBuilder(this);
               filterBuilder.AddFilter(new ContentFilterStatement("ID", itemId.ToString(), ContentFilter.Condition.Equal));
               this.CreateSingleContent();
               
               try
               {
                   Controls.Add(SingleContainer);
               }
               catch (Exception e) { }
           }
           
           
     
       }


    Greetings,
    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
Register for webinar
4 posts, 0 answered