Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

How to check if a page is displayed in EditMode or in ViewMode from codebehind

Hi, Is there any way I can check if a page is displayed in EditMode in codebehind? I would like to the print out some elements when the page loads in EditMode and some other elements when the page is displayed as normal in ViewMode. Best Regards Anders
Jan 08, 2008 13:06

Oh god. after one whole year there is no suggestions on this? Frown

Anders, did you get any answers or solution to this????? It works for me but in UGLY WAY.

I did checked URL like this. 


if (Request["idkeep"] != null)



You can also check for HttpContext.Current.User.IsInRole("WebEditors")  or any parameters that are passed only in edit mode.

It would execute the   AddSyncButton() function when page is in edit mode. 

BUT TAKE OUT  Response.Write(Request["idkeep"]);  and DOH.. my function ceases to execute. Cry

I have no clue.. WHY? It could be something to do with URL redirect by friendly URLS. May be user in the FRAME which shows page in view mode gets logged out?


I dont want to add ugly Response.Write to solve my problem.  

Apr 09, 2008 15:10

I guess easiest would be to check Querystring parameter. 

Just check the parameters you get in edit mode and plain view mode.  e.g. idkeep parameters seems to appear only on edit mode. 


Response.Write("URL: " + Request.url) .. Check  what you get when page is displayed in edit mode and in view mode. 



Apr 16, 2008 10:19

I use the following in my applications. It is not very elegant since it requires a reference to EPiServer.Configuration, but it gets the job done.

protected virtual bool InEditMode
        return EPiServer.Configuration.EPiServerSection.Instance.Sites[0].SiteSettings.UIUrl.IsBaseOf(System.Web.HttpContext.Current.Request.Url);   
I use this in my custom properties, and that is why I keep the property protected. (there is no need for consumers of my custom property to know about this property, but it could be useful for subclasses) "Virtual" because it makes it easier to mock in my unit tests.
Edited, May 08, 2008 23:29
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.