How to display a popup when saving a Sitecore item?

When I save a Sitecore element, I try to display a popup for user interaction. Depending on the data that they changed, I can display a series of 1 or 2 pop-ups asking them if they want to continue. I figured out how to connect to the OnItemSaving pipeline. It's simple. I cannot figure out how to display the popup and respond to user input. Now I think that I should somehow use the Sitecore.Context.ClientPage.ClientResponse object. Here is some code that shows what I'm trying to do:

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] } } } 

Should I use a different method? I see that there are also ShowModalDialog and ShowPopUp and ShowQuestion, etc. I can not find any documentation on them. Also, I'm not even sure if this is the right way to do something like this.

+4
source share
1 answer

The process goes something like this (I should note that I never tried this from an element: saving the event, however, I believe it should work):

  • In the item:saving event, invoke the dialog processor in the client pipeline and pass it a set of arguments.
  • A processor performs one of two actions; displays a dialog box or consumes a response.
  • When a response is received, the processor consumes it, and you can perform your actions.

Here is an example demonstrating the following steps:

 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; } } } 
+7
source

All Articles