1

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.

Utpal
  • 805
  • 4
  • 15
  • 44
  • Please specify one version of EPiServer, this is quite different in epi6 and 7 – Eric Herlitz Apr 07 '14 at 10:06
  • Your template page should probably inherit TemplatePage instead. That way you'll get the CurrentPage property (among other things) in your template to simplify accessing properties of the current page. – Ted Nyberg Feb 23 '15 at 12:52

1 Answers1

0

I assume you dont have strongly typed classes for your pages. You can get the current page from HttpContext.

var currentPage = HttpContext.Current.Handler as PageData;
var property = currentPage.Property["RestURL"].ToString();
Zepro
  • 1