How do I tell whether I am in UI or View mode from codebehind?

Vote:
 

I have already read this thread: http://world.episerver.com/Modules/Forum/Pages/thread.aspx?id=15953 which suggests either using the "idkeep" querystring parameter.

I'm getting partial success with but when I publish a page with "Composer - Edit On Page" the idkeep querystring parameter is still on the URL.

Is there a recommended way to tell whether you are in an editing interface (Composer/Standard UI) aside from the one I'm trying above?

#58574
May 01, 2012 12:26
Vote:
 

Hi,

This is one way

public static bool IsEditOrPreviewMode
{
    get
    {
        HttpRequest request = HttpContext.Current.Request;

        Uri referrer = request.UrlReferrer;

        return referrer != null &&
                referrer.Host == request.Url.Host &&
                referrer.LocalPath.EndsWith("EditPanel.aspx", StringComparison.InvariantCultureIgnoreCase);
    }
}

    

#58577
May 01, 2012 14:40
Vote:
 

Thanks for the reply. This works for the regular editor but not "Composer - Edit on page".

Are there any more alternatives? Should I have posted this in the Composer section?

#58864
May 09, 2012 15:19
Vote:
 

The Composer ExtensionHandler has a property called ViewMode that you can look at.

Eg: if (_extensionHandler.ViewMode == ExtensionGeneric.ViewMode.ExtensionEditOnPageMode || _extensionHandler.ViewMode == ExtensionGeneric.ViewMode.ExtensionEditMode)

#58870
May 09, 2012 19:57
Vote:
 

If using composer why not use Dropit.Extension.Core.BaseContentFunction.IsEditMode

#58908
May 10, 2012 16:51
Vote:
 

Hi Frederik, Thanks for your tip. How would I get the value of _extensionHandler on a masterpage? 

 

Minesh, Thanks for reply. I know this method works in a composer function, but only if it is registered. I'd ideally like to implement this on a masterpage without registering a composer function I have no plans to use.

#58937
May 11, 2012 13:02
Vote:
 

I have it in a base class for my Composer page types:

public abstract class ComposerPageBase<T> : TemplatePageBase<T> where T : TypedPageData
{
	//Add a ExtensionPageHandler to enable Composer
	private Dropit.Extension.Core.ExtensionPageHandler _extensionHandler;

	public ComposerPageBase()
	{
		_extensionHandler = new ExtensionPageHandler();
	}

	protected override void OnInit(EventArgs e)
	{
		base.OnInit(e);
		
		// Add meta tag to set default content compatible mode in IE 8
		HtmlMeta httpEquiv = new HtmlMeta();
		httpEquiv.HttpEquiv = "X-UA-Compatible";
		httpEquiv.Content = "IE=EmulateIE7";
		Header.Controls.Add(httpEquiv);

		//It's important that _extensionHandler initialized after base.OnInit.
		_extensionHandler.Initialize(this);

		if (_extensionHandler.ViewMode == ExtensionGeneric.ViewMode.ExtensionEditOnPageMode || _extensionHandler.ViewMode == ExtensionGeneric.ViewMode.ExtensionEditMode)
		{
			
		}
	}
}

    

#58938
May 11, 2012 13:18
Vote:
 

ahh i see. that works great, thanks for the help. the amusing thing is that i'm using it to set the same meta tag you have in your code snippet above!

#58979
May 15, 2012 10:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.