Bug in Dynamic Module override

Posted by Community Admin on 04-Aug-2018 12:53

Bug in Dynamic Module override

All Replies

Posted by Community Admin on 19-Aug-2013 00:00

Hi,

After upgrading to Sitefinity 6.1 I'm having troubles with this class:

public class MediaMasterListView : DynamicContentViewMaster
 

This is my own custom implemenation of the DynamicContentViewMaster and it worked perfectly before upgrading.

I  stripped it down to use all the default templates, but it always ends up with this error message:
[NullReferenceException: Object reference not set to an instance of an object.]
   Telerik.Sitefinity.DynamicModules.Web.UI.Frontend.DynamicContentViewMaster.ConfigurePager(Int32 virtualItemCount) +353
   Telerik.Sitefinity.DynamicModules.Web.UI.Frontend.DynamicContentViewMaster.InitializeControls(GenericContainer container) +284
   Telerik.Sitefinity.Web.UI.SimpleView.CreateChildControls() +87
   System.Web.UI.Control.EnsureChildControls() +188
   System.Web.UI.Control.PreRenderRecursiveInternal() +72
   System.Web.UI.Control.PreRenderRecursiveInternal() +255
   System.Web.UI.Control.PreRenderRecursiveInternal() +255
   System.Web.UI.Control.PreRenderRecursiveInternal() +255
   System.Web.UI.Control.PreRenderRecursiveInternal() +255
   System.Web.UI.Control.PreRenderRecursiveInternal() +255
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4047

Anything changed that I don't know of?
It looks like a problem with the pages, but I'm not sure what that can be.

Thanks,
Daniel

Posted by Community Admin on 22-Aug-2013 00:00

Hello Daniel

 There has been a slight change in the code. This part of the method:

this.Pager.VirtualItemCount = virtualItemCount;
              this.Pager.PageSize = this.MasterViewDefinition.ItemsPerPage.Value;
              this.Pager.QueryParamKey = this.UrlKeyPrefix;
              this.Pager.BaseUrl = this.PagerBaseUrl;
          
          else
          
              this.Pager.Visible = false;
          
was changed to:
this.Pager.VirtualItemCount = virtualItemCount;
             this.Pager.PageSize = this.MasterViewDefinition.ItemsPerPage.Value;
             this.Pager.QueryParamKey = this.UrlKeyPrefix;
             this.Pager.BaseUrl = this.PagerBaseUrl;
             if (this.Host.SetPaginationUrls.HasValue)
             
                 this.Pager.SetPaginationUrls = this.Host.SetPaginationUrls.Value;
         
         
         else
         
             this.Pager.Visible = false;
         
Can you share with part of the logic of your  custom DynamicContentViewMaster?

Regards,
Jen Peleva
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 22-Aug-2013 00:00

Hi Jen,

MediaDynamicContentView

public class MediaDynamicContentView : DynamicContentView
 
        protected override void InitializeMasterView()
 
            string str;
            if (HasValidRelatedDataConfiguration && RelatedItemsIds != null)
                MasterViewControl.SourceItemsIds = RelatedItemsIds;
            
            DynamicContentViewMaster masterViewControl = new MediaMasterListView();
            str = (string.IsNullOrEmpty(MasterViewDefinition.TemplateKey) ? DefaultMasterTemplateKey : MasterViewDefinition.TemplateKey);
            masterViewControl.TemplateKey = str;
            masterViewControl.DynamicContentType = DynamicContentType;
            masterViewControl.MasterViewDefinition = MasterViewDefinition;
            masterViewControl.UrlEvaluationMode = UrlEvaluationMode;
            masterViewControl.UrlKeyPrefix = UrlKeyPrefix;
 
            Controls.Add(masterViewControl);
 
        
    

MediaDynamicContentViewMaster
public class MediaMasterListView : DynamicContentViewMaster
 
        public override string LayoutTemplatePath
            get
 
                return _layoutTemplatePath;
            
            set
                base.LayoutTemplatePath = value;
            
 
        
 
        public override string TemplateKey
            get return null;
        
 
        protected override string LayoutTemplateName
            get return null;
        
 
        protected override void InitializeControls(GenericContainer container)
            SetSorting();
            base.InitializeControls(container);
        
 
        //<summary>
        // Sets the sorting.
        //</summary>
        //<param name="sortField">The sort field.</param>
        //<param name="sortOrder">The sort order.</param>
        private void SetSorting()
 
            var query = new QueryString(HttpContext.Current.Request.Url);
            var sortField = query.GetParameter("sortField");
            var sortOrder = query.GetParameter("sortOrder");
 
            if (string.IsNullOrEmpty(sortField))
                sortField = "publicationdate";
 
            if (string.IsNullOrEmpty(sortOrder))
                sortOrder = "descending";
 
            var currentSort = (sortOrder == "ascending") ? RadListViewSortOrder.Ascending : RadListViewSortOrder.Descending;
            var newSort = (currentSort == RadListViewSortOrder.Ascending) ? RadListViewSortOrder.Descending : RadListViewSortOrder.Ascending;
 
            switch (sortField.ToLower())
                case "publicationdate":
 
                    query.Parameters.Clear();
                    query.Parameters.Add("sortField", sortField.ToLower());
                    query.Parameters.Add("sortOrder", newSort.ToString().ToLower());
 
                    SortByDateTop.NavigateUrl = query.MakeAll();
                    SortByDateBottom.NavigateUrl = query.MakeAll();
                    SortDateTop.Attributes.Add("class", string.Format("active-0", sortOrder.ToLower()));
                    SortDateBottom.Attributes.Add("class", string.Format("active-0", sortOrder.ToLower()));
 
                    query.Parameters.Clear();
                    query.Parameters.Add("sortField", "title");
                    query.Parameters.Add("sortOrder", newSort.ToString().ToLower());
                    SortByTitleTop.NavigateUrl = query.MakeAll();
                    SortByTitleBottom.NavigateUrl = query.MakeAll();
                    SortTitleTop.Attributes.Clear();
                    SortTitleBottom.Attributes.Clear();
 
                    break;
                case "title":
 
                    query.Parameters.Clear();
                    query.Parameters.Add("sortField", sortField.ToLower());
                    query.Parameters.Add("sortOrder", newSort.ToString().ToLower());
                    SortByTitleTop.NavigateUrl = query.MakeAll();
                    SortByTitleBottom.NavigateUrl = query.MakeAll();
                    SortTitleTop.Attributes.Add("class", string.Format("active-0", sortOrder.ToLower()));
                    SortTitleBottom.Attributes.Add("class", string.Format("active-0", sortOrder.ToLower()));
 
                    query.Parameters.Clear();
                    query.Parameters.Add("sortField", "date");
                    query.Parameters.Add("sortOrder", newSort.ToString().ToLower());
                    SortByDateTop.NavigateUrl = query.MakeAll();
                    SortByDateBottom.NavigateUrl = query.MakeAll();
                    SortDateTop.Attributes.Clear();
                    SortDateBottom.Attributes.Clear();
 
                    break;
            
 
            var s = (currentSort == RadListViewSortOrder.Ascending) ? "ASC" : "DESC";
            MasterViewDefinition.SortExpression = string.Format("0 1", sortField.ToUpper(), s.ToUpper());
        
 
 
        protected override void DynamicContentListView_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
 
            var data = ((RadListViewDataItem)e.Item).DataItem as DynamicContent;
 
            var litSummary = e.Item.FindControl("litSummary") as Literal;
            litSummary.Text = data.GetValue("Summary").ToString();
 
            string url = DataResolver.Resolve(data, "URL", UrlKeyPrefix, MasterViewDefinition.DetailsPageId.ToString());
 
            var socials = new StringBuilder();
            var socialUrl = url.ToAbsoluteUrl();
            var socialTitle = data.GetValue("Title").ToString() + " #egz #zeewolde " + data.GetValue<string>("ShortUrl");
            var socialDescription = data.GetValue("Summary").ToString();
 
            socials.Append(string.Format("<a id='facebook_like' class='addthis_button_facebook_like' addthis:url='0' addthis:title='1' addthis:description='2' fb:like:layout='box_count'></a>", socialUrl, socialTitle, socialDescription));
            socials.Append(string.Format("<a id='twitter_like' class='addthis_button_tweet' tw:count='vertical' addthis:url='0' addthis:title='1' addthis:description='2'></a>", socialUrl, socialTitle, socialDescription));
            socials.Append(string.Format("<a class='addthis_counter' addthis:url='0' addthis:title='1' addthis:description='2'></a>", socialUrl, socialTitle, socialDescription));
 
            var litSocials = e.Item.FindControl("litSocials") as Literal;
            litSocials.Text = socials.ToString();
 
            base.DynamicContentListView_ItemDataBound(sender, e);
        
 
        #region Control references
 
        protected virtual Pager PagerBottom
            get
                return Container.GetControl<Pager>("pager1", true);
            
        
 
        protected virtual HyperLink SortByDateTop
            get
                return this.Container.GetControl<HyperLink>("lnkSortByDateTop", true);
            
        
 
        protected virtual HtmlGenericControl SortDateTop
            get
                return this.Container.GetControl<HtmlGenericControl>("liSortDateTop", true);
            
        
 
        protected virtual HyperLink SortByTitleTop
            get
                return this.Container.GetControl<HyperLink>("lnkSortByTitleTop", true);
            
        
 
        protected virtual HtmlGenericControl SortTitleTop
            get
                return this.Container.GetControl<HtmlGenericControl>("liSortTitleTop", true);
            
        
 
        protected virtual HyperLink SortByDateBottom
            get
                return this.Container.GetControl<HyperLink>("lnkSortByDateBottom", true);
            
        
 
        protected virtual HtmlGenericControl SortDateBottom
            get
                return this.Container.GetControl<HtmlGenericControl>("liSortDateBottom", true);
            
        
 
        protected virtual HyperLink SortByTitleBottom
            get
                return this.Container.GetControl<HyperLink>("lnkSortByTitleBottom", true);
            
        
 
        protected virtual HtmlGenericControl SortTitleBottom
            get
                return this.Container.GetControl<HtmlGenericControl>("liSortTitleBottom", true);
            
        
        #endregion
 
        private const string _layoutTemplatePath = "~/Widgets/Media/Templates/MediaMasterListView.ascx";
 
    

This code works perfect if I disable the Paging functionality.
You can debug it yourself: it will throw an Exception at this statement:
this.Pager.BaseUrl = this.PagerBaseUrl;

Inside this method:
private void ConfigurePager(int virtualItemCount)
        
            bool? allowPaging = this.MasterViewDefinition.AllowPaging;
            if ((!allowPaging.GetValueOrDefault() ? true : !allowPaging.HasValue) || !this.MasterViewDefinition.ItemsPerPage.HasValue || this.MasterViewDefinition.ItemsPerPage.Value <= 0)
            
                this.Pager.Visible = false;
            
            else
            
                this.Pager.VirtualItemCount = virtualItemCount;
                Pager pager = this.Pager;
                int? itemsPerPage = this.MasterViewDefinition.ItemsPerPage;
                pager.PageSize = itemsPerPage.Value;
                this.Pager.QueryParamKey = this.UrlKeyPrefix;
                this.Pager.BaseUrl = this.PagerBaseUrl;
                if (base.Host.SetPaginationUrls.HasValue)
                
                    Pager value = this.Pager;
                    bool? setPaginationUrls = base.Host.SetPaginationUrls;
                    value.SetPaginationUrls = setPaginationUrls.Value;
                    return;
                
            
        

Kind regards,
Daniel

Posted by Community Admin on 27-Aug-2013 00:00

Hi Daniel,

As Jen is Out of Office I am handling your request.

Thank you for the provided code snippets and explanation.

 Please note that the problem lies in the fact that the Host is null. You'll have to set the Host where you set the MasterViewControl:

protected DynamicContentViewMaster MasterViewControl
    get
    
        if (this.masterViewControl == null)
        
            this.masterViewControl = new DynamicContentViewMaster(this.DynamicManager);
            this.masterViewControl.Host = this;
        
        return this.masterViewControl;
    
    set
    
        this.masterViewControl = value;
    

Please let me know if this helps.

Regards,
Veronica
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 27-Aug-2013 00:00

Hi Veronica,

Thanks for the follow up.
This indeed fixed the problem.

Thanks!
Daniel

Posted by Community Admin on 28-Aug-2013 00:00

Hello,

I'm glad that I helped.

Please let me know if you have more questions.  

Regards,
Veronica
Telerik
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 14-Nov-2014 00:00

Hi, I'm using this approach all the time, and it works just great!

 But now I'm trying to do the same with DetailViewControl. Has anyone some insight there? Defining and initializing it the same way as for the MasterViewControl, but i only get this error:

A required control was not found in the template for "~/SfCtrlPresentation/_SFCT_/6d39cce0738702b3d1709f68d61b5d097df48ab7/DynamicContentViewDetail.ascx". The control must be assignable from type "Telerik.Sitefinity.DynamicModules.Web.UI.Frontend.DynamicDetailContainer" and must have ID "detailContainer".

What puzzles me is that SF is trying to load this ascx, since my custom DynamicContentViewDetail has it's LayoutTemplatePath set to my own file.

Any insight?

OC

Posted by Community Admin on 19-Nov-2014 00:00

Hi,

The most probable reason for the error might be if the view is not able to find a DynamicDetailContainer control which has the id "detailContainer":

<sf:DynamicDetailContainer id="detailContainer" runat="server">
    <LayoutTemplate>      
           
    </LayoutTemplate>
</sf:DynamicDetailContainer>

Most probably you have modified the template and the control above might have been removed. Can you please check this on your side?

Please note that by design the default widget expects template with certain required controls which should be present in order the widget to work properly. 

Regards,
Sabrie Nedzhip
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed