Adding confirmation to page actions of administration interface

This post shows a few more things how Kentico global event handling can be extended to add more functionality to Kentico admin interface without need to modify Kentico built-in controls.

Let's imagine the situation that you need to show some javascript confirmation box to Kentico editor when he saves the data he has entered on the Form or Page tab of Kentico administration. You may ask what the reason is to show confirmation dialog when save the form? There might be a lot of tricky tasks and requirements that will require to do this. For example, you have a lot of documents on the site that are linked to different places under content tree. Editor of one site decided to modify content in some linked article. So you decided just to remind the Editor that he saves the linked document and if he don't want the changes influence all the linked documents the system will simply create a copy of this document. Another thing that might happen - you want to disable some header action (for example for some complicated workflow logic).

To implement such requirements you can find the file of the header action control in the Kentico project and add your logic to the code of that control. But as we may know modifying Kentico build-in controls is not really good practice as after upgrade to newer Kentico version your code might be rewritten and you will need to add this logic again. Do you agree? :)

So Kentico event handling is become handy here. More information about Kentico global event hanling might be found here: Handling global events. Code sample below demonstrate how to add javascript confirmation dialog on 'Save' action. You can access all page header action buttons and their properties and modify them accordingly. And it is all about subscription to OnAfterUserControlPreRender event and handling this event appropriately. You may add any required logic to that method according to the requirements you have. 

using System;
using System.Collections.Generic;
using CMS.Base;
using CMS.Controls;
using CMS.DocumentEngine;
using CMS.ExtendedControls;
using CMS.ExtendedControls.ActionsConfig;
using CMS.PortalEngine;
using CMS.SiteProvider;

public partial class CMSModuleLoader
    /// <summary>
    /// Custom attribute class for the CMSModuleLoader.
    /// </summary>
    private class CustomizationLoaderAttribute : CMSLoaderAttribute
        /// <summary>
        /// Called automatically when the application starts.
        /// </summary>
        public override void Init()
            //Assigns handler to display popup message
            EditMenu.OnAfterUserControlPreRender= EditMenu_OnAfterUserControlPreRender;

        private void EditMenu_OnAfterUserControlPreRender(object sender, EventArgs e)
            HeaderActions headerActions = sender as HeaderActions;

            if (headerActions != null && headerActions.ActionsList.Count > 0)
                if (PortalContext.ViewMode == ViewModeEnum.EditForm || PortalContext.ViewMode == ViewModeEnum.EditLive || PortalContext.ViewMode == ViewModeEnum.Edit)
                    List<HeaderAction> saveActionsList = headerActions.ActionsList.FindAll(p => p.EventName == "Save");
                    foreach (HeaderAction action in saveActionsList)
                        action.OnClientClick += "return confirm(\"Do you want to save the document?\");";

If you find this post usefull please leave your comments below. Thanks in advance, Mariia.

bdsm paddles
nice bLog! its interesting. thank you for sharing.... <a href=""></a>
9/17/2017 7:14:32 PM

Sex Positions
If your looking for Online Illinois license plate sticker renewals then you have need to come to the right place.We offer the fastest Illinois license plate sticker renewals in the state.
8/26/2017 7:58:28 PM

Pacquiao vs Horn Live Stream
Pacquiao vs Horn live stream free HBO PPV boxing online. watch Manny Pacquiao vs Jeff Horn live streaming fight card at Queensland, Australia on 2 July 2017.
7/1/2017 4:19:17 AM

omega replique
hello!! This is a good selling high-end watch site <a href="http://www.swiss-replica.co.uk/category/omega/"> omega replique</a>
6/10/2017 9:32:01 AM

hot sale replica watches
Out of work, party, you may need a watch to reflect your temperament and vision, to show you different from the general taste and vision. Here to meet your needs. thank.
5/17/2017 1:59:59 AM

nike air max
Ultra-cool Nike running shoes<a href="http://www.homesgb.co.uk/">nike air max 1 black</a>
Have this running shoes you can go to the peak of life
Your fate is destined to need such a running shoes
5/16/2017 3:40:08 AM

klockor kopior
This is a great watch
Successful person's selection[url=http://www.bet-result.com/]kopior klockor[/url]
Identity status symbolizes only one watch to prove your advantage
You just need a symbol of this watch
5/9/2017 2:57:45 AM

klockor kopior
This is a great watch
Successful person's selection<a href="http://www.bet-result.com/">klockor kopior</a>
Identity status symbolizes only one watch to prove your advantage
You just need a symbol of this watch
5/9/2017 2:51:06 AM

Ultimately, a dilemma that I'm passionate about. I have looked for data of this caliber for the previous various hours. Your internet site is greatly appreciated.
5/5/2017 9:36:34 PM

Ultimately, a dilemma that I'm passionate about. I have looked for data of this caliber for the previous various hours. Your internet site is greatly appreciated.
5/5/2017 9:36:14 PM

View Image Must Need It looks like Richard just doesnt do it for Christy anymore!
5/5/2017 9:35:58 PM

united states, price for viagra Join us know.
5/4/2017 10:36:53 PM

SPECIAL OFFER : For Women Herbal on SALE , Buy Viagra For Women Herbal shop online .
5/4/2017 10:36:47 PM

old computer equipment disposal
This article is an appealing wealth of informative data that is interesting and well-written. I commend your hard work on this and thank you for this information. You’ve got what it takes to get attention.
4/10/2017 2:56:16 PM

seo price plans
I have a hard time describing my thoughts on content, but I really felt I should here. Your article is really great. I like the way you wrote this information.
4/4/2017 6:40:15 AM

Very nice site! <a href="http://ypxoiea.com/ovyvorv/1.html">cheap viagra</a>
3/22/2017 4:00:08 PM

Hello! cgffcfc interesting cgffcfc site! I'm really like it! Very, very cgffcfc good!
3/22/2017 3:59:55 PM

Very nice site! <a href="http://ypxoiea.com/ovyvorv/1.html">cheap viagra</a>
3/22/2017 3:28:10 PM

Hello! dckedke interesting dckedke site! I'm really like it! Very, very dckedke good!
3/22/2017 3:28:00 PM

Generic can be purchased at any pharmacy or online pharmacy for a small price.
3/22/2017 7:33:32 AM

However, fast delivery some items for females, exploitation rub-down the.
3/22/2017 1:27:57 AM

Buy Online For Full Customer Satisfaction - FDA Approved (/about/constructi on.
3/21/2017 9:49:41 PM

Click Here to see if you qualify for patient assistance now.
3/21/2017 9:49:12 PM

This really is actually fascinating, That you are a quite specialist blogger. Ive joined your rss feed and sit up for looking for more of your excellent post. Also, I have shared your web site in my social networks!
1/11/2017 2:15:45 PM

I simply couldn't depart your web site prior to suggesting that I actually loved the usual info a person supply for your guests? Is gonna be again continuously in order to check up on new posts.
11/12/2016 6:03:20 PM

I'm curious to uncover out what weblog system youre employing? Im experiencing some small security problems with my latest weblog and Id like to locate something a lot more safeguarded. Do you have any recommendations?
10/15/2016 10:08:17 AM

Real nice design and great articles, nothing else we want
10/12/2016 6:39:31 AM

Real nice design and great articles, nothing else we want
10/12/2016 6:38:44 AM

Fantastic beat ! I wish to apprentice while you amend your website, how can i subscribe for a blog web site? The account aided me a acceptable deal. I had been a little bit acquainted of this your broadcast offered bright clear concept
10/7/2016 11:51:39 AM

Wow! This could be one particular of the most useful blogs We've ever arrive across on this subject. Actually Excellent. I'm also an expert in this topic so I can understand your hard work.
10/4/2016 8:16:23 AM

Very efficiently written information. It will be beneficial to everyone who employess it, including myself. Keep up the good work for sure i will check out more posts.
9/27/2016 1:07:52 PM

Keep working ,impressive job!
9/26/2016 11:29:34 AM

I think this is a real great blog post.Much thanks again.
9/22/2016 2:25:12 PM

Have you ever considered about including
9/22/2016 9:55:00 AM

 Security code