Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Displaying a common property on a master page

Vote:
 

Newbie... please be gentle.

I'm building a simple site. It currently has two page types, "Start" and "CommonPage". The "Start" page type has a property called "CommonDisclaimer". This property needs to be displayed in the footer of every page.

So, in my master page, I use the following:

<EPiServer:Property ID="Disclaimer" PropertyName="CommonDisclaimer" PageLink="<%#EPiServer.Core.PageReference.StartPage%>" runat="server" />

It works great on the homepage, but not on any of the inner pages, where I instead see a "[Error: No property "CommonDisclaimer".] message.

Oddly, if I replace the PageLink attribute with the ID of the home page, it works correctly on every page.

<EPiServer:Property ID="Disclaimer" PropertyName="CommonDisclaimer" PageLink="3" runat="server" />

Any ideas? I'm really hoping not to have to resort to the code-behind for such a simple task.

Thanks in advance.

#38670
Apr 16, 2010 22:32
Vote:
 

I meant to clarify. The start page of the site uses the "Start" page type. Also, I'm using CMS 6.

#38671
Apr 16, 2010 22:35
Vote:
 

I think it's a databinding problem.  The PageLink property doesn't bind automatically.

I recreated your situation.  It didn't work for me until I put this in this code-behind:

Disclaimer.DataBind();

It worked fine for me after that.

#38673
Apr 16, 2010 23:20
Vote:
 

Thanks Deane. Adding the DataBind works.

So, is this issue a quirk/bug with episerver? Shouldn't the control do the binding automatically? Or is this just how .NET is suppose to work?

#38674
Apr 16, 2010 23:34
Vote:
 

Controls don't databind automatically.  But if you just call "DataBind" in the code-behind, it will bind every control on the page in one shot.

It wouldn't be hard to extend the EPiServer Property control as a "StartPageProperty" control which automatically bound it to the StartPage and so always pulled properties from there.  If you have a number of these, that's what I'd do.  It would be, maybe, 2-3 lines of code beyond the default class structure.

#38675
Apr 16, 2010 23:44
Vote:
 

Ah that makes sense. Thanks again Deane.

#38676
Apr 17, 2010 0:04
Vote:
 

Just for fun:

 

using System;
using EPiServer.Core;

namespace Blend.EPiServer.Controls
{
    public class StartPageProperty : global::EPiServer.Web.WebControls.Property
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            PageLink = PageReference.StartPage;
            DataBind();
        }
    }
}

In web.config, under pages/controls:



Then, in the master page:



 

#38677
Edited, Apr 17, 2010 0:06
Vote:
 

Nice. Thanks for the code. Very helpful!

#38682
Apr 17, 2010 18:59
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.