Try our conversational search powered by Generative AI!

Access values of a property from another aspx file

Vote:
 

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.

#57030
Feb 22, 2012 10:07
Vote:
 

I might add a bit from the code behind file

using ...

namespace ...

public partial class ... : ...

public string Event1Link;

more code

#57031
Feb 22, 2012 10:18
Vote:
 

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;

    

#57041
Feb 22, 2012 13:25
Vote:
 

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.

 

#57044
Edited, Feb 22, 2012 14:38
Vote:
 

as page perhaps works =)

#57045
Feb 22, 2012 14:44
Vote:
 

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;

    

#57046
Feb 22, 2012 14:45
Vote:
 

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&auml;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.

 

 

 

#57047
Feb 22, 2012 15:35
Vote:
 

Sorry for the strange formating.

#57048
Feb 22, 2012 15:35
Vote:
 

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!!

#57049
Edited, Feb 22, 2012 15:42
Vote:
 

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.  

#57050
Edited, Feb 22, 2012 15:43
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.