EPiServer  /  CMS November 30, 2012

EPiServer 7 – How to check if the page is in edit mode

Need to know if an EPiServer CMS page is being rendered in edit mode or not? Then the PageEditing class is your friend.

After trying a number of ways to determine if a page or block is rendered within EPiServer CMS’ edit mode or not I stumbled upon a nice little helper class in the EPiServer API named PageEditing. Using this we can easily check if the current request is for a content object in edit mode in templates and preview pages:

//using EPiServer.Editor;

bool inEditMode = PageEditing.PageIsInEditMode;

I tried this for both pages and block in Web Forms as well as with MVC and it seems to work everywhere.

The PageEditing class also has a couple of other nice members, such as the method GetEditUrl for retrieving the URL for editing a content object  and GetChannel which returns the current channel, if any.

PS. For updates about new posts, sites I find useful and the occasional rant you can follow me on Twitter. You are also most welcome to subscribe to the RSS-feed.

Joel Abrahamsson

Joel Abrahamsson

I'm a passionate web developer and systems architect living in Stockholm, Sweden. I work as CTO for a large media site and enjoy developing with all technologies, especially .NET, Node.js, and ElasticSearch. Read more

Comments

comments powered by Disqus

My book

Want a structured way to learn EPiServer 7 development? Check out my book on Leanpub!

More about EPiServer CMS