CustomProperty is NULL after upgrading

Vote:
 

I'm having some issues with a custom page property which worked fine in v6, but not in v7. It seems like the values previously populated in the property is gone. On page load my custom property (CurrentPage.Tags) is always NULL. However, if a add a new value to the property, the property is no longer NULL - but only showing the new value(s), not values stored pre-v7.

Here's the basic layout of the custom property:

From the PageType class:

        [BackingType(typeof(PropertyTags))]
        [Display(Name = "Tags",
            Description = "",
            Order = 3100,
            GroupName = Helper.ContentTypeGroupNames.InformationTab)]
        public virtual CategoryList Tags { get; set; }

The custom property class:

 [Serializable]
    [PropertyDefinitionTypePlugIn(DisplayName = "Tags", Description = "Tag selector")]
    public class PropertyTags : PropertyCategory
    {
        public override IPropertyControl CreatePropertyControl()
        {
            return new TagsControl();
        }
    }

The TagsControl class:

public class TagsControl : PropertyStringControl
    {

        public override void CreateEditControls()
        {
         // add ui-interface for add/removal of strings
        }

        protected override void OnPreRender(EventArgs e)
        {
            // populate ui-interface
        }

        public override void ApplyEditChanges()
        {
           // save changes
        }
     
    }

Any ideas to why this is happening?

#89886
Aug 28, 2014 9:17
Vote:
 

This is the original custom property (haven't changed much)

Edit:

I found a work-around which gets the job done, for now:

var tagsCategory = EPiServer.DataAbstraction.Category.Find("Tags");
var categoriesForCurrentPage = CurrentPage.Category;
var tagsForCurrentPage = new CategoryList();

foreach (int catId in categoriesForCurrentPage)
{
if (tagsCategory.FindChild(catId) != null) tagsForCurrentPage.Add(catId);
}

#89889
Edited, Aug 28, 2014 10:02
Vote:
 

Now I've made a temporary work-around by doing the following

var tagsCategory = EPiServer.DataAbstraction.Category.Find("Tags");
            var categoriesForCurrentPage = CurrentPage.Category;
            var tagsForCurrentPage = new CategoryList();

            foreach (int catId in categoriesForCurrentPage)
            {
                if (tagsCategory.FindChild(catId) != null) tagsForCurrentPage.Add(catId);
            }


Which works fine for now.

[Pasting files is not allowed]

#89894
Edited, Aug 28, 2014 11:22
Vote:
 

Having some trouble editing posts here...

I made a work-around which gets the job done:

var tagsCategory = EPiServer.DataAbstraction.Category.Find("Tags");
            var categoriesForCurrentPage = CurrentPage.Category;
            var tagsForCurrentPage = new CategoryList();

            foreach (int catId in categoriesForCurrentPage)
            {
                if (tagsCategory.FindChild(catId) != null) tagsForCurrentPage.Add(catId);
            }
#89895
Aug 28, 2014 11:36
Vote:
 

That is the old way of doing custom properties.
Joel describe nearly the exact same custom prop here and how he solved it to be able to use it in a legacymode

http://joelabrahamsson.com/upgrading-a-site-from-episerver-cms-6-to-episerver-7/

#89950
Aug 29, 2014 7:15
Vote:
 

Thank you Henrik, that did the trick!

#89955
Aug 29, 2014 8:09
Vote:
 

Great to know OerjanH!

#89958
Aug 29, 2014 8:31
Vote:
 

I seems I still have some strange behavior going on. The custom property will work fine as long as I've edited the property and published the page. However, initially, before editing the custom property, the property will be NULL when accessed in the template. Eventually, I will probably either migrate to another tag plug-in or at least convert the legacy property to Dojo.

The following gets the job done until then

            if (CurrentPage.Tags != null && CurrentPage.Tags.Count > 0)
            {
                DoSomethingWithTheData(CurrentPage.Tags.ToArray());
            }
            else
            {
                var tagsCategory = EPiServer.DataAbstraction.Category.Find("Tags");
                var categoriesForCurrentPage = CurrentPage.Category;
                var tagsForCurrentPage = new CategoryList();
 
                foreach (int catId in categoriesForCurrentPage)
                {
                    if (tagsCategory.FindChild(catId) != null) tagsForCurrentPage.Add(catId);
                }

                DoSomethingWithTheData(tagsForCurrentPage.ToArray());
            }
#90463
Sep 10, 2014 10:53
Vote:
 

Just an update:

After upgrading from 7.0 to 7.5 (7.13.3) I am no longer having this issue. 

#90871
Sep 19, 2014 14:51
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.