Search code examples
sitecoresitecore8customdialog

Sitecore 8 - How to - Custom Pop up via code + ClientPage is null


I am trying to show a popup message on the content editor on click of publish . I have my handler called in the "publish:begin"event.

    public void PublishCatcherDialog(object sender, EventArgs args)
    {
        //Some custom code here including "id" declaration
        ClientPipelineArgs args = new ClientPipelineArgs();
        args.Parameters.Add("id", id);
        Sitecore.Context.ClientPage.Start(this, "DialogProcessor", args);
    }

However I see that in Sitecore 8 , Sitecore.Context.ClientPage.Start gives a null exception error , so does "SheerResponse". Most blogs out there have the code for a button click trigger that gives the appropriate command context and Sitecore.Context . How to do in in this scenario (code triggered)?

If you suggest Speak , where would I declare the .js association to this pipeline? I see the sitecore dlls still use this above code to show modal dialogs , so it cannot be completely obselete... I feel am missing a simple inheritance somewhere that would set the context .


I need to trigger the alert when I click on the "Publish" button on the publish wizard dialog. It looks like a "submit" action on publishform.aspx

Image here


Solution

  • Edit 1

    Since you need to show a popup when the user click on the publish button, you will need to override the Sitecore Publish XML UI found in the path Website/sitecore/shell/Applications/Dialogs/publish.

    Copy the Publish.xml and paste it in the Override folder. Path is Website\sitecore\shell\Override. Note that the folder may be empty. To keep the standard create the same directory structure. Example: Website\sitecore\shell\Override\Applications\Dialogs\publish

    Now create a class that should inherite the Sitecore.Shell.Applications.Dialogs.Publish.PublishForm

    Your code will be as follows:

    using Sitecore.Shell.Applications.Dialogs.Publish;
    
    public class PublishWizardOverride : PublishForm
    {
        protected override void OnNext(object sender, EventArgs formEventArgs)
        {
            // Your code to display your popup goes here
    
            base.OnNext(sender, formEventArgs);
        }
    }
    

    Then open the copied xml file from the Override folder and change the CodeBeside with your namespace and assembly

    Note: You may required to check the page on which the user is so that the popup does not appear on all Next Button clicks.