Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

CreatePropertyControl by using IPropertyControlFactory

Vote:
 

According to the breaking changes for EPiServer 11:

CreatePropertyControl has been removed from PropertyData. Use IPropertyControlFactory instead to register and create controls for PropertyData types.

But how do I do this in the following code?

    [Serializable]
    [PropertyDefinitionTypePlugIn(DisplayName = "Sorting right column")]
    public class RightColumnSortorder_Property : PropertyString
    {
        public override IPropertyControl CreatePropertyControl()
        {
            return (IPropertyControl)BuildManager.CreateInstanceFromVirtualPath("~/Templates/Util/RightColumnSortorder_PropertyControl.ascx", typeof(RightColumnSortorder_PropertyControl));
        }
    }



#190849
Apr 17, 2018 16:58
Vote:
 

No one?

If I inherit the IPropertyControlFactory instead of PropertyString - I'll need to implement some methods. How should they look like?

    public class RightColumnSortorder_Property : IPropertyControlFactory
    {
        public override IPropertyControl CreatePropertyControl()
        {
            return (IPropertyControl)BuildManager.CreateInstanceFromVirtualPath("~/Templates/FMV/Util/RightColumnSortorder_PropertyControl.ascx", typeof(RightColumnSortorder_PropertyControl));
        }

        public IPropertyControl CreatePropertyControl(PropertyData propertyData)
        {
            throw new NotImplementedException();
        }

        public bool IsRegistered<TPropertyData>() where TPropertyData : PropertyData
        {
            throw new NotImplementedException();
        }

        public IPropertyControlFactory Register<TPropertyData>(Func<IPropertyControl> controlFactory) where TPropertyData : PropertyData
        {
            throw new NotImplementedException();
        }

        public IPropertyControlFactory Register<TPropertyData, TPropertyControl>()
            where TPropertyData : PropertyData
            where TPropertyControl : IPropertyControl
        {
            throw new NotImplementedException();
        }

        public IPropertyControlFactory Unregister<TPropertyData>() where TPropertyData : PropertyData
        {
            throw new NotImplementedException();
        }
    }

I've two custom properties that are "simple". But I also have one more advanced property that overrides several methods that seems to be missing in IPropertyControlFactory like: ParseToObject(), SetDefaultValue() and so on.

#191162
Apr 23, 2018 8:28
Vote:
 

Hi

You could register your property control from an IInitializableModule like:

    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    public class PropertyControlRegisterModule : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            context.Locate.Advanced.GetInstance<IPropertyControlFactory>().Register<RightColumnSortorder_Property>(() =>
                (IPropertyControl)BuildManager.CreateInstanceFromVirtualPath("~/Templates/Util/RightColumnSortorder_PropertyControl.ascx", typeof(RightColumnSortorder_PropertyControl)));
        }

        public void Uninitialize(InitializationEngine context)
        {
        }
    }
#191163
Apr 23, 2018 9:08
Vote:
 

Adding the IInitializableModule and removing CreatePropertyControl() I was able to build the project, but my custom properties ends up as a regular textbox and a datepicker in edit-mode. So no success this far :(

    [InitializableModule]
    [ModuleDependency(typeof(EPiServer.Web.InitializationModule))]
    public class PropertyControlRegisterModule : IInitializableModule
    {
        public void Initialize(InitializationEngine context)
        {
            //RightColumnSortorder_Property
            context.Locate.Advanced.GetInstance<IPropertyControlFactory>().Register<RightColumnSortorder_Property>(() =>
                (IPropertyControl)BuildManager.CreateInstanceFromVirtualPath("~/Templates/Util/RightColumnSortorder_PropertyControl.ascx", typeof(RightColumnSortorder_PropertyControl)));

            //ArchiveDate_Property
            context.Locate.Advanced.GetInstance<IPropertyControlFactory>().Register<ArchiveDate_Property>(() =>
                new ArchiveDate_PropertyControl());

        }

        public void Uninitialize(InitializationEngine context)
        {
        }
    }

The RightColumnSortorder_PropertyControl.ascx looks looks like this. Implementing IPropertyControl

public partial class RightColumnSortorder_PropertyControl : UserControlBase, IPropertyControl { //... }

And the ArchiveDate_PropertyControl looks like:

public class ArchiveDate_PropertyControl : EPiServer.Web.PropertyControls.PropertyDateControl { //... }

Something else I need to add/change?

#191185
Edited, Apr 23, 2018 15:52
Vote:
 

The edit mode is not rendered through WebForms but from a javascript framework. So to customize the edit experience in edit mode you would need to do something like described in 

https://world.episerver.com/documentation/developer-guides/CMS/editing/Registering-a-custom-editor/

#191210
Apr 24, 2018 9:12
Vote:
 

Ok, I was affraid of that. Good point about edit mode and WebForms. Thanks

#191223
Apr 24, 2018 10:06
Vote:
 

How to implement IPropertyControlFactory Methods in episerver 11? Previously I can override methods inherited from PropertyString Class but now how to do it in upgraded version?

#193823
Jun 05, 2018 15:37
Vote:
 

You are not supposed to implement IPropertyControlFactory, instead you register a custom factory method for your custom property. In example below (more detail is in previous post in this thread) a web control ArchiveDate_PropertyControl is registered for custom property ArchivedDate_Property

  context.Locate.Advanced.GetInstance<IPropertyControlFactory>().Register<ArchiveDate_Property>(() =>
                new ArchiveDate_PropertyControl());
#193884
Jun 07, 2018 9:27
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.