Im using epi 5sp2 and i got a page which is a newslist and under it i got pages that are newsitems. The hierarchy of the structure is Startpage-newslist-newsitem. The problem is when i set properties of a property at the newslist the newsitem should retrieve it and display the value at the page. Ive done this by getting a pageref to the newslist at the newsitem page by :
1. PageReference ParentRef = PageReference.ParseUrl(CurrentPage["pagereftoparent"] as string);
2. If not null then
3.checking that something excists
4. PageData Parent = DataFactory.Instance.GetPage(ParentRef);
5. check that its not null and if its not null
6. PageData Page = CurrentPage.CreateWritableClone();
Page["SocialMedia"] = Parent["SocialMedia"]; //property on parent is saved to a property on Page
The whole event is triggered at the saved Event and im following the instructions of how to save one page's property to another page's property but i get the following errors/faults:
1. the property doesnt get saved to newsitem page. When i make the value visible its empty.
2. When i save Newslist page a second time and it contains newsitem it says that the pageref is empty and i get error. Despite that im checking if the value of the pageref is null or empty.
Ok so im following the textbook practice of how to save a property in code behind but it just wont do and frankly there isnt much documented about it.So if someone has a solution or could point me in a direction it would be much appriciated.
Do you have to save the value from the newslist on the actual newsitem?
I'm not sure if you can save the page with that saveaction. You must put it together with SaveAction.Save or SaveAction.Publish, like so: SaveAction.ForceCurrentVersion | SaveAction.Publish. To be able to save a current version yo must also get the specific version of the page. Dig it out using PageVersion.List(pageRef);
hmm, not sure that i HAVE to save it on the newsitem page. Im guessing that i could just show the value, dont know which to prefer!?
ok, will try that. strange that i have to go away from what the "textbook" says (atleast the material i have). perhaps poor dokumentation?
Will let you know how it went...
I would definetely just get the value from the parent page.
Some pseudo code:
parent = GetPage(NewsItempage.ParentLink);
if (parent != null && parent["propertyname"] != null)
I didn't read very carefully, I focused on the SaveAction part. And yes, you need to combine the ForceCurrentVersion with Save or Publish, not as sure about the version thing though now that you say you've seen a different example. Where did you find that.
Otherwise I agree with Per, don't duplicate the data if you have a way to get it from the newslist. If you are just going to display it you can also use the episerver Property control and set its PageLink property to make it read from a different page, for example:
<EPiServer:Property runat="server" PropertyName="MyProp" PageLink='<%#CurrentPage.ParentLink%>' />
hmm, ok well the best choice is to go with the Property control, but ill use the code behind for other selection ill have to make.
However im using:
EPiServer:Property runat="server" PropertyName="SocialMedia" PageLink='<%#CurrentPage.ParentLink%>' DisplayMissingMessage="false" />
but the panel is still empty and ive set the property values in parent page. The property on the parent page is a custom made property, will this effect the output?
Sorry, it is using databinding syntax so you need to give the control an ID and call DataBind() on it from codebehind. Or you could set the PageLink property from CodeBehind. If you want the parent page you can also get away with just markup if you use the PageLinkProperty property cleverly:
EPiServer:Property runat="server" PropertyName="SocialMedia" PageLinkProperty="PageParentLink" />
Magnus youre a saint and perhaps epi god. Well the easiest way to do it is to use the last suggestion you had, without adding code behind. If you are going to do more advanced stuff then perhaps code behind is to prefer and use Per's contribution but this is simple enough...
cheers all and thnx for the help.