Loading

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;

[CustomizationLoader]
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.


Comments
juegos friv
Hey very nice site!! Man .. Beautiful .. Amazing .. I will bookmark your blog and take the feeds alsoI am happy to find a lot of useful info here in the post, we need work out more techniques in this regard, thanks for sharing. . . . . .
2/8/2018 3:56:08 AM

soft
Which is better for ed , viagra, or levitra?
1/24/2018 12:21:16 PM

di
There has negative setbacks posed by diabetics for walgreens prices all packages.
1/23/2018 9:16:48 AM

net
Your book there is for a generic cover, left, to return, they rely on more expensive.
1/23/2018 9:16:37 AM

تور تایلند
Nice post. Thank you for the info. Keep it up.
12/23/2017 11:24:15 AM

James
Aw, this was a very nice post. In thought I want to put in writing like this moreover taking time and actual effort to make an excellent article but what can I say I procrastinate alot and not at all seem to get something done.
12/9/2017 9:09:08 AM

James
Aw, this was a very nice post. In thought I want to put in writing like this moreover taking time and actual effort to make an excellent article but what can I say I procrastinate alot and not at all seem to get something done.
12/9/2017 9:08:44 AM

Capital Gains Tax Advice
Thank you for helping people get the information they need. Great stuff as usual. Keep up the great work!!!
12/6/2017 5:25:28 PM

connexion republic
We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up. Great work.
12/4/2017 7:13:16 AM

123movies
Many thanks for sharing this very diverse opinion post where each expert has no doubt shared his best knowledge on the topic. Have more success in your journey.
11/20/2017 9:42:46 AM

MyPsychLab
nice post, keep up with this interesting work. It really is good to know that this topic is being covered also on this web site so cheers for taking time to discuss this!
11/19/2017 10:05:38 AM

MyPsychLab
nice post, keep up with this interesting work. It really is good to know that this topic is being covered also on this web site so cheers for taking time to discuss this!
11/19/2017 10:05:12 AM

slader
Thanks for taking the time to discuss that, I feel strongly about this and so really like getting to know more on this kind of field. Do you mind updating your blog post with additional insight? It should be really useful for all of us.
11/18/2017 6:45:24 AM

mastering biology
I read that Post and got it fine and informative.
11/16/2017 2:19:19 PM

remy hair extensions
Golden brown egg hair extensions roll wig, egg roll perm way also can highlight the modeling of hair extensions sale playful and three-dimensional sense. Thick side of bangs easy to face contour into a delicate face, egg roll head unique but playful cute beauty makes hair extensions store people put it down.
11/10/2017 1:44:16 AM

hair
good
11/2/2017 1:37:03 AM

waqar mazhar
thans for posting
10/31/2017 4:32:41 PM

James
This kind of game gives a real experience of
10/4/2017 1:19:30 AM

paypal
DMOZ Categories DMOZ categories for top--store-online.
10/2/2017 7:54:29 AM

progressive metal
Song of love heavy metal music is here to serve you in your metal riffs needs You are tired of what the world has become people are listening to garbage music and they do not know it download heavy metal music.Download heavy metal music what your soul needs is not to listen to fake music anymore because it affects you You need to listen to heavy metal music Song of love Download heavy metal music Song of love.
9/23/2017 12:35:53 PM

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

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

James
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

James
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

loans
View Image Must Need It looks like Richard just doesnt do it for Christy anymore!
5/5/2017 9:35:58 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

Charles
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

Richard
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

Michael
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

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

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

James
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

David
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

Paul
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

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

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

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

 Security code