Loading...

Last updated: Dec 09 2016

Area: Episerver CMS Applies to versions: 10 and higher
Other versions:

Creating UI settings for dynamic content (Legacy)

Note: Dynamic content is deprecated. Use blocks instead. While existing solutions will continue to work, you should not build new solutions on this API. It will be phased out in the future.

When you develop dynamic content functionality, you may want the editor to enter some settings when adding dynamic content to a page. The following sections show how to create user interface settings for dynamic content in Episerver.

Creating UI settings automatically using PropertyDataCollection

If you just want some simple fields (any field that is a property in Episerver), you can use a PropertyDataCollection that automatically will be rendered in the settings user interface for this dynamic content. When you create a dynamic content plug-in you inherit from the IDynamicContentBase interface. One member of IDynamicContentBase is:

public PropertyDataCollection Properties
{
    get;
}

Any PropertyData in the collection is rendered for the editor to see and change. The collection also is updated with any changes the editor makes.

Creating UI settings with a user control

If you want a more advanced settings user interface, or just want more control, you can load your own user control. That is done by adding an attribute to your dynamic content, and supplying a Url attribute:

[GuiPlugIn(Url = "~/MyDynamicContentSettings.ascx", Area = PlugInArea.DynamicContent)]
public class MyDynamicContent : IDynamicContent

DynamicContentEditControl

The dynamic content settings control needs to inherit from DynamicContentEditControl:

public partial class MyDynamicContentSettings : DynamicContentEditControl

DynamicContentEditControl is an abstract class that supplies your class with one property, DynamicContent, and forces you to implement one method PrepareForSave(). The DynamicContent property gives you a reference to your dynamic content and PrepareForSave() is called when the user clicks OK in the settings user interface. The following example shows how they can be used on an edit control:

public override void PrepareForSave() 
   {
     ((MyDynamicContent)DynamicContent).Name = NameTextBox.Text; 
     ((MyDynamicContent)DynamicContent).Age = AgeSelector.Value;
   }

In the example, MyDynamicContent has two properties, Name and Age, which have values from the control located in the markup. Then MyDynamicContent plug-in handles the values and persists the internal state which occurs through the implementation of the State property.


Do you have feedback on this documentation? Send an email to documentation@episerver.com. For development-related questions and discussions, refer to our Forums on https://world.episerver.com/forum/