Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.
Join us this Friday for AI in Action at the Virtual Happy Hour! This free virtual event is open to all—enroll now on Academy and don’t miss out.
I might add a bit from the code behind file
using ...
namespace ...
public partial class ... : ...
public string Event1Link;
more code
Do you mean that you want to fetch a text from the start page and present it on different aspx templates? If so, you can create a property in each code behind file and return the value from the property on the startpage.
PageData startPage = DataFactory.Instance.GetPage(PageReference.StartPage);
return startPage["MyProperty"] as string;
Johan: thank you very much! The problem is that the property on the page type is of type 'Sida' (a type I guess the developer has made some how).
I tried this but it doesnt work
PageData startPage = DataFactory.Instance.GetPage(PageReference.StartPage);
var FirstEvent = startPage["FirstEvent"] as object;
OutPut.Controls.Add(FirstEvent);
// asp:PlaceHolder with id OutPut, on aspx template
I also tried 'as sida' but then Visual Studio say that a reference is missing.
Are you sure that the type i 'Sida' and not PageReference?
var firstEvent = startPage["FirstEvent"] as PageReference;
if (firstEvent != null)
{
// Do your stuff
}
You can't add the object as a control to the output though. You need to render it before. But I'm not sure what you try to acomplish here.
Can't you just use the EPiServer Property Control to render the output?
<EPiServer:Property PropertyName="FirstEvent" ID="MyProp" runat="server" />
And in code behind
this.MyProp.PageLink = PageReference.StartPage;
Johan: Ok I will try and explain more precisly.
'default.aspx' is a page template that is used on the the page type 'startsida'.
default.aspx's front end has the following code
<div class="event">
<a href="<%= Event1Link %>"><span class="row"><span class="date"><%= Event1Date %></span> <span class="time">
<%= Event1Time %></span> <span class="location"><%= Event1Place %></span> <span class="cc">
</span></span><span class="header"><%= Event1Header %></span> <span class="bread">
<%= Event1Text %><span class="more">
Läs mer</span></span></a></div>
default.aspx's back end has alot of code. Like:
public string str;public string Event1Date;public string Event1Time;public string Event1Place;public string Event1Header;public string Event1Text;public string Event1Link;
PageDataCollection myPages = new PageDataCollection();
PageReference page = CurrentPage["FirstEvent"] as PageReference;
PageData Event0 = DataFactory.Instance.GetPage(page);
PageReference page2 = CurrentPage["SecondEvent"] as PageReference;
PageData Event1 = DataFactory.Instance.GetPage(page2);
PageReference page3 = CurrentPage["ThirdEvent"] as PageReference;
PageData Event2 = DataFactory.Instance.GetPage(page3);
myPages.Add(Event0);
myPages.Add(Event1);
myPages.Add(Event2);
The pagetype 'startsida' has three propertys of the type 'sida' (page?), Iam looking in admin mode. When an editor browse to a page in EpiServer and place in the controller some text is written to the startpage of our web site.
My goal is to have the same text written to another page. The editor in EpiServer works as usual with the startpage pagetype and the content is written to both the startpage and to the other page.
I think I solved it. Oh lord. Much thanks to you Johan.
This "PageData startPage = DataFactory.Instance.GetPage(PageReference.StartPage);" did the trick, in the code behind of the new file
I think. I gonna take a break from this now, my head hurts. I check everything to morrow. If it works I mark your post as "answer".
Thank you very much!!
Not sure if I understand you. But I guess your problem is this code:
PageReference page = CurrentPage["FirstEvent"] as PageReference;
PageData Event0 = DataFactory.Instance.GetPage(page);
PageReference page2 = CurrentPage["SecondEvent"] as PageReference;
PageData Event1 = DataFactory.Instance.GetPage(page2);
PageReference page3 = CurrentPage["ThirdEvent"] as PageReference;
PageData Event2 = DataFactory.Instance.GetPage(page3);
myPages.Add(Event0);
myPages.Add(Event1);
myPages.Add(Event2);
You are fetching the properties from CurrentPage, and CurrentPage is the startpage only when you´re on the startpage.
If you change the code to:
PageData startPage = DataFactory.Instance.GetPage(PageReference.StartPage);
PageReference page = startPage["FirstEvent"] as PageReference;
PageData Event0 = DataFactory.Instance.GetPage(page);
PageReference page2 = startPage["SecondEvent"] as PageReference;
PageData Event1 = DataFactory.Instance.GetPage(page2);
PageReference page3 = startPage["ThirdEvent"] as PageReference;
PageData Event2 = DataFactory.Instance.GetPage(page3);
myPages.Add(Event0);
myPages.Add(Event1);
myPages.Add(Event2);
Your're allways looking at the startpage properties and not the CurrentPage.
Hi all!
I have an aspx file named default.aspx. On the page template there are propertys(?) like this
<%= Event1Link %>
there is also code behind code, alot of it.
If I have another aspx file, withing the same project, but it uses another masterpage file, can I access the values of those propertys?
Basicly what Iam trying to do is this:
- An editor in EpiServer types text into fields
- That text is written on the start page
- Now, I also want that text to be written on another page based on another page template
Thank you very much.