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

Vote:
 
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
#15953
Jan 08, 2008 13:06
Vote:
 

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. 

Response.Write(Request["idkeep"]);

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

{              
                AddSyncButton();
 }  
  

 

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.  

#19385
Apr 09, 2008 15:10
Vote:
 

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. 

 

 

#19538
Apr 16, 2008 10:19
Vote:
 

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
{
    get
    {
        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.
#19858
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.