Try our conversational search powered by Generative AI!

Getting the property value of a page



I am very new to EpiServer and I want to develop a code for accessing property values of a page. I can access that using this code 

        PageData oPage = EPiServer.DataFactory.Instance.GetPage(new PageReference(30))
        string str = oPage.Property["RestURL"].ToString();
        TextBox1.Text = str;

but this is very hardcoded . So i want to access it dynamically like currentpage property values. but below code is giving error object reference is not set to an instabce of object.

public partial class Templates_Public_Pages_Scheduling : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        //PageData oPage = EPiServer.DataFactory.Instance.GetPage(new PageReference());
        //PageData oPage = EPiServer.DataFactory.Instance.GetPage(new PageReference(;
        PageData oPage = EPiServer.DataFactory.Instance.CurrentPage;
        string str = oPage.Property["RestURL"].ToString();
        TextBox1.Text = str;
        //Property property = CurrentPage["propertyname"];  

Please help me to overcome this.


Mar 28, 2014 14:42

I don't think EPiServer.DataFactory.Instance.CurrentPage actually returns the current page. Try to inherit from EPiServer.TemplatePage  instead of System.Web.UI.Page, then you will get a CurrentPage property to work with.

Edited, Mar 28, 2014 15:22

When your request hits page that inherits from `System.Web.UI.Page` it has almost nothing to do with EPiServer context. You have to tell EPiServer that his is your page and it will give you most of the stuff you need. As Erik mentioned - inherit from TemplatePage. Or even better - it's a good practice to create your own base class (let's say TemplatePageBase, that inherits from TemplatePage) and use that. Will give you single place to add custom stuff unique and required for your project pages.

Mar 28, 2014 15:29

Hi ,

Then it is giving this error.


RightClickMenu requires a header control on the page. (e.g. <head runat="server" />).


markup is like this


<form runat="server">
           <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
But no master page file is used


Edited, Mar 28, 2014 15:31

If you don't have runat="server" in the head tag, then you can inherit from SimplePage instead. You will not get the Right click menu though.

Mar 28, 2014 15:33
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.