Blog about tips & tricks for CMS enhancement

eric.petersson

Super simple check for edit mode in Episerver


Episerver 6 check

When is comes down to Episerver 6, there is no given built in method to check if a page is currently being presented in the Episerver edit mode. For various reasons this may be achieved by the following simple extension:

using EPiServer.Core;

public class MyEpiExtensions
{
    public bool IsEditMode
    {
        get { return WorkPageID > 0; }
    }
}

By looking for the workpage id greater than 0, Episerver will recognize the difference between the different modes.

In a user control you may set some special logics for the edit mode like the following example:

<%@ Import Namespace="MyEpiExtensions" %>

<% if (MyEpiExtensions.IsEditMode) { %>
    <!-- //... code -->
<% } %>