Inherit from DynamicContentBase instead of implementing the IDynamicContent interface.
It will take care of the State management for your custom properties and let you focus on implementing the actual Dynamic Content Element.

Example
    public class HelloWorld : DynamicContentBase
    {
        private PropertyString nameProperty;

        public HelloWorld()
        {
            nameProperty = new PropertyString();
            nameProperty.Name = "Name";
        }

        public override System.Web.UI.Control GetControl(PageBase hostPage)
        {
            throw new NotImplementedException();
        }

        public override EPiServer.Core.PropertyDataCollection Properties
        {
            get {
                if (properties == null)
                {
                    properties = new PropertyDataCollection();
                    properties.Add(nameProperty);
                }
                return properties;
            }
        }

        public override string Render(PageBase hostPage)
        {
            return "Hello "+nameProperty.ToWebString();
        }

        public override bool RendersWithControl
        {
            get { return false; }
        }
    }

Last edited Oct 23, 2009 at 10:55 PM by AllanThraen, version 1

Comments

No comments yet.