November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Hi
I think CreatedPage is raised after the page has been saved, so any changes you make to the PageData object won't be persisted. Try the CreatingPage event instead, it's raised during the save process. Or perhaps LoadingDefaultPageData or LoadedDefaultPageData would be even better, if you want to set a default value.
Regards
Per Gunsarfs
EPiServer Development Team
Tested the creatingpage event, no success. The loadingdefaultdata and loadingdefaultdata is raised before the page is created? If I use them I cant check which pagetype the page is, because is doesnt exist.
void Instance_CreatingPage(object sender, EPiServer.PageEventArgs e)
{
if (e.Page.PageTypeID == PropertyHelper.GetPropertyFromSettingsPage<int>("InfoPageType"))
{
if (!e.Page.IsValue("PageResponsible"))
{
string user = PrincipalInfo.CurrentPrincipal.Identity.Name;
MembershipUserCollection users = Membership.GetAllUsers();
foreach (MembershipUser u in users)
{
if (user == u.UserName)
{
PageData clone = e.Page.CreateWritableClone();
clone.Property["PageResponsible"].Value = user;
DataFactory.Instance.Save(clone, EPiServer.DataAccess.SaveAction.Publish); } } } } }
As Per says, LoadedDefaultPageData should do the trick, but not sure if they've changed the way it works.
http://antecknat.se/blog/2008/06/09/prepopulate-fields-when-creating-page/
I have a custom property (dropdown list) that I want to set automaically when a page is created. The custom property have to be editable when the page is created.
I have tried to create a DataFactory.Instance.CreatedPage += new PageEventHandler(Instance_CreatingPage); in global where I set my custom property and save. DataFactory.Instance.Save(clone, EPiServer.DataAccess.SaveAction.ForceCurrentVersion); but the property is not set after the page is published. Ideas anyone?