通常,当我想访问Sitecore中的当前项目时,我会通过Sitecore.Context.Item
。在创建最终用户使用的工具时,此功能会很好,但不适用于Sitecore管理员使用的工具。如果我想在Content Editor
本身中显示某个自定义字段,则Context.Item
是对Content Editor
的引用,而不是在编辑器中选择的节点。如何从Sitecore内容编辑器的自定义字段访问父项目?
大多数情况下,我可以通过使用ItemID
属性来解决此问题,但是如果我在该字段上有事件调度程序,则这些将不再有权访问ItemID。例如:
protected override void OnPreRender(EventArgs e)
{
if (IsEvent)
{
// ItemID is defined here!
Button live = FindControl(GetID(LiveButton)) as Button;
if (live != null)
{
live.ServerProperties["Click"] = string.Format("{0}.LiveClicked", ID);
}
}
}
public void LiveClicked()
{
// ItemID is blank here!
DoSomething();
}
如何获取项目ID在我的监听器(像LiveClicked
以上)?
我意识到这不是自定义字段实际应该做的事情,但客户已明确声明他希望在内容编辑器的主体中具有某些功能。 – cwallenpoole 2013-05-07 18:32:36