In editmode or not?

Hi, Is there any easy way to figure out if a page is rendered within the editmode. I guess I could look on the url but wouldnt really wanna do that. It should be done from the code-behind too. /Johan
Jun 07, 2005 15:48
I made the following method as a QnD solution to check this: public bool isInEditMode (PageBase myP) { bool ret = false; if (null != myP.Request.UrlReferrer && (myP.Request.UrlReferrer.ToString().IndexOf("edit") >= 0 || myP.Request.UrlReferrer.ToString().IndexOf("Edit") >= 0 || myP.Request.UrlReferrer.ToString().IndexOf("admin") >= 0 || myP.Request.UrlReferrer.ToString().IndexOf("Admin") >= 0)) { ret = true; } return ret; } /mats d.
Jun 07, 2005 16:20
The suggested function above would return true when visiting a page from ex. SomePageWithEditOrAdminInTheName.aspx I'd make sure you actually start of with either /edit/ or /admin/ ex. public bool isInEditMode() { return Regex.IsMatch(HttpContext.Current.UrlReferrer.LocalPath, "^/admin/|^/edit/", RegexOptions.IgnoreCase); } or unless you want to include the uses for System.Web and System.Text.RegularExpressions public bool isInEditMode() { return System.Text.RegularExpressions.Regex.IsMatch(System.Web.HttpContext.Current.UrlReferrer.LocalPath, "^/admin/|^/edit/", System.Text.RegularExpressions.RegexOptions.IgnoreCase); } However none of these function return true if you navigate in Edit-mode by clicking a link on the page in preview. As far as I know there are no really good solution to this problem. One thing one might do is to subclass EPiServer.Edit.PreviewControl (the control used for the iframe in edit mode, and of course change ) and have it add a cookie with a very low expiredate?
Jun 27, 2005 13:15
This would be a nice feature in the next release (4.6)! An easy solution would be to send "&mode=preview" in the querystring when browsing trough the edit gui. Maybe this is possible to do with a plugin to extend current releases?! Regards, Micke
Jun 27, 2005 14:46
That's pretty easy... add a new usercontrol to you project... have this in your codebehind and leave the codefront empty using System; using System.Web; namespace EPiServer.Edit.MyOwnReplacement { public class PreviewControl : EPiServer.Edit.PreviewControl { private void Page_PreRender(object sender, EventArgs e) { if (PreviewUrl.LastIndexOf('?') != -1) { PreviewUrl += "&mode=preview"; } else { PreviewUrl += "?mode=preview"; } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.PreRender += new EventHandler(Page_PreRender); } #endregion } } then goto /edit/EditPanal.aspx and change the following line to load your modified preview control <%@ Register TagPrefix="EPiServer" Namespace="EPiServer.WebControls" Assembly="EPiServer" %> to <%@ Register TagPrefix="edit" TagName="PreviewControl" Src="~/ThePathAndNameOfTheControl.aspx"%>
Jun 28, 2005 8:56
Nice. This should work well until EP includs the solution into EPiServer. Maybe 4.6?! ;) Regards, Micke
Jun 28, 2005 9:57
* 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.