I’m writing an account registering control. This control needs to show the user how to register for a new account. But when modifying this control the pages editors must be able to see the hole flow. So I went looking for a smart way to display the control in two ways depending on the context it’s being viewed in. I found Jacob Khan’s blog post in EPiServer labs that seemed nice but I didn’t get it to work.
The thing I ended doing was to get the id from the query string, and parsing it to a PageReference to check if it contains a workID. The ID in the QueryString has both the pages ID and the current version being edited, for example 1563_1234 where 1563 is the pages ID and 1234 is the current version.
If the QueryString contains a work page ID it means that I'm currently looking at a draft, not the published page, hence I´m in Edit mode.
When getting the WorkID of a PageData object that's published you will get 0 as a result, and that's what I'm testing against.
Here is the code
public bool IsPageInEditMode
{
get
{
PageReference pageVersionReference = PageReference.Parse(Request.QueryString["id"]);
if (pageVersionReference.WorkID > 0)
return true;
return false;
}
}