Hi,
I'm struggling to persist changes to a dynamic property on a page.
I have an event handler hooked onto the CreatedPage event. I also have a dynamic property defined called guidIdentity.
In the event handler I want to set this dynamic property to the value of a new guid and persist this change.
I have the following code in the event handler:
DataFactory.DynPropTree.SetDynamicProperties(pageData);
string guid = Guid.NewGuid().ToString();
pageData.Property["guidIdentity"].Value = guid;
EPiServer.Global.EPDataFactory.Save(pageData,EPiServer.DataAccess.SaveAction.Publish);
When i view the page in edit mode and edit dynamic properties the value is empty. Any ideas why this is the case?
Many thanks.
Ah, it seems that although the dynamic property appears to be a property, that in fact is not really the case when it comes to changing the value.
There is a another, somewhat undocumented, way to update a dynamic property in code.
The following works:
DynamicPropertyCollection dynaprops = DynamicProperty.ListForPage(e.PageLink);
DynamicProperty dp = dynaprops["guidIdentity"];
dp.PropertyValue.Value = "some value";
DynamicProperty.SaveCollection(e.PageLink, dynaprops);
An addition to the book/ docs on this would be useful. All the examples are read only and give the impression that dyna props work the same way as normal properties.