Creating page properties dynamically

Vote:
 
I'm trying to dynamically add properties to a page but am having trouble persisting them. My test code is something like: protected void Page_Load(object sender, EventArgs e) { CurrentPage = CurrentPage.CreateWritableClone(); CurrentPage.Property.Add("myProperty" + DateTime.Now.Ticks, new EPiServer.SpecializedProperties.PropertyXhtmlString()); DataFactory.Instance.Save(CurrentPage, EPiServer.DataAccess.SaveAction.Publish); } What I expect to happen is that every time i load the page an extra property will be added. However the property never seems to be saved. I.e. when I load the page again the property has disappeared. i haven't been able to find any sample code to do this. Can someone tell me if I'm approaching it in the right way?
#16032
Mar 19, 2008 18:39
Vote:
 
Hi! You have to add the additional property to the page definition (page type) before you can save the property to a page. Linus Ekström EPiServer Development Team
#16851
Mar 20, 2008 11:10
Vote:
 
Ahh. So it's impossible to add new properties to a single instance of a page? I'll explain my use case and perhaps you could tell me if there's an alternative way of achieving it. I want to create a landing-page page type. This landing page will have introductory panels for each sub page. Eg. if there were 4 sub pages there would be 4 individually editable panels on the page. If there are 6, then there would be 6 panels etc. Obviously I could create a 4 panel page type and a 6 panel page type, but this obviously isn't very scalable. What I was trying to achieve is when a user would create a sub page a new panel (XHTML String Property) would be automatically added to the parent landing-page thus allowing the user the freedom to add as few or as many pages as they want. Note that the design demands that each panel be separately editable in the cms. Thanks for any help.
#16852
Mar 20, 2008 11:59
Vote:
 
It cannot be done, the properties must be part of the definition (the page type.) Why not put the xhtml long string on the subpage itself, and from the landing page, get the xhtml long string from the subpage, but show it on the landing page. The xhtml long string does not have to show on the subpage, its only purpose is to be shown on the landing page. /Steve
#16853
Mar 20, 2008 16:19
Vote:
 
Thanks Steve, I'll keep that in mind. I've already started down a different road though. Instead of trying to add properties I will set up the properties in the page definition (say a max of 10) and then hide them as appropriate. I.e. if there are 5 sub pages I will try to hide/remove the last 5 properties from the user. I think having all the panels editable in one place is preferable from a user's point of view.
#16854
Mar 20, 2008 16:58
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.