Try our conversational search powered by Generative AI!

Question about SaveAndView and PageReference



I have a page which has "Title" property:

CurrentPage["Title"] is has value - "Test";

When I change "Title" property to "AnotherTest" and click  Save and view button in edit mode, the change is reflected on the page.

CurrentPage["Title"] is "AnotherTest"

 But when I'm using this (current page is with id 6):

PageReference pageRef = new PageReference(6);

PageData pageData = GetPage(pageRef)

pageData["Title"] is still equal to "TestTitle"

Is there a way to get the modified property through GetPage() method?

Mar 25, 2009 16:39
Hi Vladimir!

When you are retrieving the page like that (with GetPage) you are getting the published version, but when you are using CurrentPage (in that situation) you are getting the version that you are currently viewing. The solution to your problem is dependent on what you are trying to do, but maybe this is a none-issue as it will work when the page is published?

If you need the last saved version something like this should work (though there might be a better way):

PageVersion lastSavedVersion = DataFactory.Instance.ListVersions(new PageReference(6)).OrderByDescending(version => version.Saved).First();
PageData lastSavedPageData = DataFactory.Instance.GetPage(lastSavedVersion.ID); 

Edited, Mar 25, 2009 16:51

Just to clearify, the problem is in the line:
PageReference pageRef = new PageReference(6);

When you create a new PageReference with just a pageId in the constructor, you will automatically get the published version. And since you stated you only clicked Save and View you are not publishing the new version.

So what you can do is either specify the version:
PageReference pageRef = new PageReference(6, XXX);
PageData pageData = GetPage(pageRef);

Or do the really long walk with CurrentPage:
PageReference pageRef = new PageReference(CurrentPage.PageLink);
PageData pageData = GetPage(pageRef);

Or do the short walk:
PageData pageData = CurrentPage;

Because CurrentPage always uses the page version if it can...

Best regards
Fredrik Karlsson

Mar 25, 2009 20:01
The problem is when I'm using a control on a masterpage which loads the page through a dynamic property. The dynamic property may or may not have the same PageReference as the currently viewed page. This is why I cannot use CurrentPage[]. The solution with ListVersions works fine. Thank you guys for the suggestions.
Mar 27, 2009 14:34
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.