How can I set page properties programmatically?
It's not a problem for build in properties like PageName... but properties defined in my PageType will just not last.
For example when I create a page:
...
PageData newPageData = Global.EPDataFactory.GetDefaultPageData(parentLink, pageTypeName);
newPageData.PageName = "Testname" // no problem
// but
newPageData.Property["MyOwnStringProperty"] = "Teststring" // will not work
// neither does
newPageData["MyOwnStringProperty"] = new PropertyString("Teststring);
// or
newPageData.Property["MyOwnStringProperty"].value = new PropertyString("Teststring);
// or any other combination I have tried.
....
the property is actually saved but only temporarily
What am I doing wrong?
You haven't actually done anything wrong, it just takes a little more code to persist new page properties. Please have a look at this FAQ article for more info:
http://www.episerver.com/templates/faq.aspx?id=4895
That FAQ actually describes how to manipulate page types in code, normally you add your property "MyOwnStringProperty" in admin mode as a one-time configuration on the page type and then just assign a page property a value, look at the "How to: Create a Page Programatically" in the SDK for an example.
Regarding assigning a property, here are your alternatives..
Alt1.
newPageData["MyOwnStringProperty"] = "Teststring";
Alt 2
newPageData.Property["MyOwnStringProperty"].value = "Teststring";
Thank you,
I wasn't actually creating a page property just assigning. But the sample code showed me the way. I hadn't saved the page after setting the property ;)
/René