保存 Sitecore 项目时,我尝试显示一个弹出窗口以与用户交互。根据他们更改的数据,我可能会显示一系列 1 或 2 个弹出窗口,询问他们是否要继续。我已经弄清楚如何利用 OnItemSaving 管道。这很简单。我不知道如何显示弹出窗口并对用户的输入做出反应。现在我认为我应该以某种方式使用 Sitecore.Context.ClientPage.ClientResponse 对象。这是一些代码,显示了我正在尝试做的事情:
public class MyCustomEventProcessor
{
public void OnItemSaving(object sender, EventArgs args)
{
if([field criteria goes here])
{
Sitecore.Context.ClientPage.ClientResponse.YesNoCancel("Are you sure you want to continue?", "500", "200");
[Based on results from the YesNoCancel then potentially cancel the Item Save or show them another dialog]
}
}
}
我应该使用不同的方法吗?我看到还有 ShowModalDialog 和 ShowPopUp 和 ShowQuestion 等。我似乎找不到任何关于这些的文档。我什至不确定这是否是做这样的事情的正确方法。
该过程是这样的(我应该注意,我从未在 item: saving 事件中尝试过此操作,但是,我相信它应该有效):
- 内
item:saving
事件,调用客户端管道中的对话处理器,并向其传递一组参数。
- 处理器执行以下两件事之一:显示对话框,或消耗响应。
- 收到响应后,处理器会使用它,您可以在那里执行操作。
下面是一个演示上述步骤的示例:
private void StartDialog()
{
// Start the dialog and pass in an item ID as an argument
ClientPipelineArgs cpa = new ClientPipelineArgs();
cpa.Parameters.Add("id", Item.ID.ToString());
// Kick off the processor in the client pipeline
Context.ClientPage.Start(this, "DialogProcessor", cpa);
}
protected void DialogProcessor(ClientPipelineArgs args)
{
var id = args.Parameters["id"];
if (!args.IsPostBack)
{
// Show the modal dialog if it is not a post back
SheerResponse.YesNoCancel("Are you sure you want to do this?", "300px", "100px");
// Suspend the pipeline to wait for a postback and resume from another processor
args.WaitForPostBack(true);
}
else
{
// The result of a dialog is handled because a post back has occurred
switch (args.Result)
{
case "yes":
var item = Context.ContentDatabase.GetItem(new ID(id));
if (item != null)
{
// TODO: act on the item
// Reload content editor with this item selected...
var load = String.Format("item:load(id={0})", item.ID);
Context.ClientPage.SendMessage(this, load);
}
break;
case "no":
// TODO: cancel ItemSavingEventArgs
break;
case "cancel":
break;
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)