通常,當我想訪問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