Is page in Edit mode

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;
    }
}
Technorati-taggar: ,

Print | posted on Monday, August 31, 2009 2:40 PM Filed Under .NET C# developement EPiServer

Comments

Gravatar

# re: Is page in Edit mode, Posted by snow boots for women on 10/15/2010 11:10 AM

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.

Gravatar

# re: Is page in Edit mode, Posted by blake on 5/27/2011 12:16 AM

Ooh, query strings are always hit and miss. I looked online for a company that can back up data for you (one of them was http://www.neverfailgroup.com). That way, if you want to change the coding at all, you have a good plan in place and can prevent disaster (and avoid a tough meeting with your IT director).

Comments

Title: *
Name: *
Email: (never displayed)
Website:
Comment: *  
Please add 7 and 5 and type the answer here: