This content is archived. See latest version here

Table of contents


When working with content data in EPiServer CMS, the default way to render content in a template is to use the property web control, <EPiServer:Property> (see EPiServer.Web.WebControls.Property). That control will be responsible for adding the required HTML in order for it to be editable in the content editing view. However, if you render your content some other way you need to make sure that the output contains the HTML attributes that the content editing view requires.

So a common scenario would be to add a wrapping HTML element around the rendered content. Set runat="server" on the element and call the property from the code behind.

<EPiServer:Property PropertyName="MyProperty" runat="server" />

Applying edit attributes to a custom control

The best way to add the attributes required for editing is to use the method EPiServer.Web.ApplyEditAttributes. It is an extension method to the System.Web.UI.Control class. Add a wrapping HTML element around the rendered content. Set runat="server" on the element and call ApplyEditAttributes on it from the code behind.

Applying full refresh properties

Some properties can affect the rendering of several parts of the page. For instance, you may have a boolean value on your page type that enables/disables several panels. To get a correct preview of such a property you would need to do a full refresh of the page.

To make a set of properties force a full reload on change, use the web control EPiServer.Web.WebControls.FullRefreshPropertiesMetaData. It will render an HTML element for all properties registered in the collection EPiServer.PageBase.FullRefreshProperties.


The following example shows how to use these methods in a template:

<EPiServer:FullRefreshPropertiesMetaData runat="server" />

<h1 runat="server" id="HeadingOne">
    <%-- Render the Heading property, unless it it empty, then use PageName as fallback --%>
    <%: CurrentPage.Heading ?? CurrentPage.PageName %>

<EPiServer:Property Runat="server" PropertyName="MainBody" />
using System;
using EPiServer;
using EPiServer.Core;
using EPiServer.Web;
using EPiServer.DataAnnotations;

namespace CodeSamples
    public partial class CustomEditHints : TemplatePage<MyPageType>
        protected override void OnLoad(EventArgs e)

            // Connect the content div to the Heading property of MyPageType
            HeadingOne.ApplyEditAttributes<MyPageType>(p => p.Heading);

            // Register the ShowBanner property for full refresh preview
            EditHints.AddFullRefreshFor(p => p.ShowBanner);

    public class MyPageType : PageData
        public virtual string Heading { get; set; }
        public virtual XhtmlString MainBody { get; set; }
        public virtual bool ShowBanner { get; set; }

Last updated: Mar 31, 2014