我是EpiServer的新手,我想开发一个访问页面属性值的代码。我可以使用此代码访问它
PageData oPage = EPiServer.DataFactory.Instance.GetPage(new PageReference(30))
string str = oPage.Property["RestURL"].ToString();
TextBox1.Text = str;
但这是非常硬编码的。所以我想像currentpage属性值一样动态访问它。但是下面的代码是给出错误对象引用没有设置为对象的instabce。
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"];
}
}
请帮助我克服这一点。
答案 0 :(得分:0)
我假设您的网页没有强类型的类。您可以从HttpContext获取当前页面。
var currentPage = HttpContext.Current.Handler as PageData;
var property = currentPage.Property["RestURL"].ToString();