【发布时间】:2013-05-08 02:30:21
【问题描述】:
通常,当我想访问 Sitecore 中的当前项目时,我会通过 Sitecore.Context.Item。这适用于创建最终用户使用的工具,但不适用于 Sitecore 管理员使用的工具。如果我想在 Content Editor 本身中显示为自定义字段,Context.Item 是对 Content Editor 的引用,而不是对在编辑器中选择的节点的引用。
在大多数情况下,我可以通过使用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();
}
如何在我的侦听器中访问 ItemID(如上面的 LiveClicked)?
【问题讨论】:
-
我意识到这不是自定义字段真正应该做的事情,但客户明确表示他希望内容编辑器的主体中具有某些功能。
标签: sitecore