A client was using CurrentPage.Changed.ToShortDateString() for displaying a Last updated date in the inner footer of their pages. They often, however, forgot to select the Mark page as changed-checkbox on the Settings tab, and asked me if it was possible to have it selected by default. Here is a simple way to do it.
Global.asax.cs
public class Global : EPiServer.Global { protected void Application_Start(Object sender, EventArgs e) { EditPanel.LoadedPage += new LoadedPageEventHandler(AutoSelectMarkPageAsChangedCheckbox); } protected void AutoSelectMarkPageAsChangedCheckbox(EditPanel sender, LoadedPageEventArgs e) { e.Page["PageChangedOnPublish"] = true; }
In your Global.asax.cs file, add an event handler to the EditPanel’s LoadedPage event. Then use the LoadedPageEventArgs to change the value of the property. PageChangedOnPublish above is the checkbox Mark page as changed.
Wouldn’t it be more elegant solution to ceate class decorated with plugin attribute and within Start() method in that plugin subscribe to DataFactory PublishingPage event? No need for Global modiciation and makes solution more “plugable” – just throwaway plugin and you loose your feature if not required anymore…
Thank you for the feedback, it is much appreciated. I agree with you that it would be much prettier to put the code in a class with InitializableModule (or use the PagePlugInAttribute in EPiServer 5), especially if it was more than a few lines of code. I’ll update the post with an example when I find the time.
The PublishingPage event however is not what I was after; it fires when a page is published and I wanted the editors to still have the possibility to deselect the checkbox should they want to.
Thanks for reminding me about PageChangedOnPublish, good stuff :)