Oh god. after one whole year there is no suggestions on this?
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.
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.
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.
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.