Try our conversational search powered by Generative AI!

Cannot save custom settings for a Property

Vote:
 

Hi Guys

I have created a custom property which allows a user to select a number of PageTypes located in a MultiSelect control, I wanted to limit the page types which get shown in this control so decided to use Custom settings, so i can select the page types i would want to show in my property.

The issue i am having is everytime i select the PageTypes via a checkbox and try to save i get the following error : Property Id must be of type System.Guid or EPiServer.Data.Identity

Just as a test I added another TextBox field as well into here to see if i edit only this would my settings save and yes they do save as long as i do not select any page types in the checkbox list.


Has anyone came across this before ?

Code below for Settings Class

    [EPiServerDataContract]
    [EPiServerDataStore(AutomaticallyRemapStore = true)]
    [PropertySettingsUI(AdminControl = typeof(PageTypeSelectorSettingsUI))]
    [Serializable]
    public class PageTypeSelectorSettings : IPropertySettings
    {
        public PageTypeSelectorSettings()
        {
            PageTypes = null;
            TestTemp = string.Empty; 
        }

        #region Public Properties

        [EPiServerDataMember]
        public PageTypeCollection PageTypes { get; set; }

        [EPiServerDataMember]
        public string TestTemp { get; set; }

        #endregion

        #region Implementation of IPropertySettings

        public IPropertySettings GetDefaultValues()
        {
            return new PageTypeSelectorSettings();
        }

        public IPropertySettings Copy()
        {
            var settings = new PageTypeSelectorSettings();
            settings.PageTypes = this.PageTypes;
            settings.TestTemp = this.TestTemp; 
            return settings; 
        }

        public Guid Id { get; set; }

        #endregion

    Code below for SettingsUI

    public class PageTypeSelectorSettingsUI : PropertySettingsControlBase
    {
        #region Constants and Fields

        private CheckBoxList pageTypeCollection;
        private TextBox tempTest; 

        #endregion


        #region Overrides of PropertySettingsControlBase

        public override void LoadSettingsUI(IPropertySettings propertySettings)
        {
            this.EnsureChildControls();
            var settings = propertySettings as PageTypeSelectorSettings;
            if (settings == null)
            {
                return;
            }

            if (settings.PageTypes != null)
            {
                foreach (var pageType in settings.PageTypes)
                {
                    ListItem myListItem = this.pageTypeCollection.Items.FindByText(pageType.Name);
                    myListItem.Selected = true;
                }
            }

            this.tempTest.Text = settings.TestTemp; 
        }

        public override void UpdateSettings(IPropertySettings propertySettings)
        {
            this.EnsureChildControls();
            var settings = propertySettings as PageTypeSelectorSettings;
            if (settings == null)
            {
                return;
            }

            settings.PageTypes = GetPageTypeCollection();
            settings.TestTemp = tempTest.Text;          
        }

        #endregion

        #region Methods

        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            this.pageTypeCollection = new CheckBoxList{ID = "PageTypeList"};
            this.pageTypeCollection.RepeatColumns = 3;
            this.pageTypeCollection.RepeatDirection = RepeatDirection.Vertical;
            this.pageTypeCollection.RepeatLayout = RepeatLayout.Table;
            this.pageTypeCollection.CssClass = "epi-dataTable"; 

            this.pageTypeCollection.DataSource = (object)PageType.List();
            this.pageTypeCollection.DataTextField = "Name";
            this.pageTypeCollection.DataValueField = "ID";
            this.pageTypeCollection.DataBind();


            var label = new Label { Text = "Page Types", AssociatedControlID = "PageTypeList" };
            this.AddNewRow(label, this.pageTypeCollection);

            this.tempTest = new TextBox { ID = "TempText" };
            var labtest = new Label { Text = "Test", AssociatedControlID = "TempText" };
            this.AddNewRow(labtest, this.tempTest);
        }


        private PageTypeCollection GetPageTypeCollection()
        {
            var collection = new PageTypeCollection();
            foreach (ListItem listItem in this.pageTypeCollection.Items)
            {
                if (listItem.Selected)
                {
                    int id = int.Parse(listItem.Value);                    
                    collection.Add(PageType.Load(id));                     
                }
            } 
            return collection;
        }

        #endregion
    }

    

 

#59035
May 17, 2012 18:27
Vote:
 

example of the issue can be seen here : http://screencast.com/t/0Tr8y2c3Vqm

#59036
May 17, 2012 19:13
Vote:
 

My initial thoughts are PageTypeCollection cannot be saved into the DDS so will try converting this into an IntegerCollection

#59043
May 18, 2012 11:36
Vote:
 

After a bit of faffing around and changing the PropertyType this is now working. I changed it to string value and saving the options as Comma delimiated integers.

#59078
May 18, 2012 16:59
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.