1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / "Pages" Module and event catcher

"Pages" Module and event catcher

4 posts, 0 answered
  1. iOleksiy
    iOleksiy avatar
    6 posts
    Registered:
    07 Apr 2008
    20 Apr 2008
    Link to this post
    Hello, support.

      Simple question - can I attach handmade C# class static method to the some of Pages module action. For example "OnPageCreated", "OnPageDeleted"?
      Thanks.

    Best regards,
      Oleksiy.
  2. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    21 Apr 2008
    Link to this post
    Hi Oleksiy,

    Yes you can. I am sorry that we don't have this documented at the moment, because it is nearly impossible to figure this out on your own.

    As you perhaps know, every logical part of Sitefinity has a manager class. So for example, when you wish to work with Blogs API, you would use BlogManager class, for News NewsManager class and so on.

    Telerik.Cms assembly is in charge of working with pages (and quite a few other things, but that's irrelevant at the moment). Following the "manager class" logic, Telerik.Cms assembly has CmsManager class, which is the one you will need.

    CmsManager class has two static events, namely "Executing" and "Executed". So, in order to handle them, you would need something like this (it's just a user control code-behind that doesn't really do anything. It's just a syntax reference):

    using System;  
    using System.Collections;  
    using System.Configuration;  
    using System.Data;  
    using System.Web;  
    using System.Web.Security;  
    using System.Web.UI;  
    using System.Web.UI.HtmlControls;  
    using System.Web.UI.WebControls;  
    using System.Web.UI.WebControls.WebParts;  
     
    using Telerik;  
    using Telerik.Cms;  
     
     
    public partial class EventsAPI_PageEvents : System.Web.UI.UserControl  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            // subscribe to CmsManager static Executed event (Executing is very similar)  
            CmsManager.Executed += new EventHandler<Telerik.ExecutedEventArgs>(CmsManager_Executed);  
        }  
     
        // this method receives ExecutedEventArgs, which will send you the name of the  
        // command that has been executed and the object on which the command has been  
        // executed (in this case that is IPage type of object)  
        private void CmsManager_Executed(object sender, ExecutedEventArgs e)  
        {  
            IPage myPage = (IPage)e.Data;  
     
            switch (e.CommandName)  
            {  
                case "CreatePage":  
                    // do something here  
                    break;  
                case "UpdatePage":  
                    // do something here  
                    break;  
                case "DeletePage":  
                    // do something here  
                    break;  
            }  
        }  

    Now, as you may have guessed "Executing" is fired while one of the commands ("CreatePage", "UpdatePage", "DeletePage") is being in progress, while "Executed" when it's done. The two EventArgs are almost identical, except that during the "Executing" you have the option to cancel operation.

    As for the command names, they are pretty straightforward:
    - "CreatePage" > page is being created for the first time
    - "UpdatePage" > change is being made to the already existing page
    - "DeletePage" > page is being deleted

    I hope this was helpful. I am sorry that this has not been documented yet, but we are starting to work on some major improvements in developer documentation, so hopefully in the future you won't have to make intelligent guesses about our API.

    Best wishes,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. iOleksiy
    iOleksiy avatar
    6 posts
    Registered:
    07 Apr 2008
    21 Apr 2008
    Link to this post
    Hello, Ivan.

      Many thanks for such full reply. Small question left - where to put or to register created control?

    Best regards,
      Oleksiy.
  4. Ivan
    Ivan avatar
    478 posts
    Registered:
    16 Jun 2015
    24 Apr 2008
    Link to this post
    Hi Oleksiy,

    Sorry for not replying sooner.

    I am not sure which version of the Developer Manual you are using at the moment, but if you download the latest version available from this page http://www.sitefinity.com/support/documentation.aspx you can find a pretty good tutorial that will answer your question.

    Navigate to Services > Custom services > Translator Services. The section explains a good approach to handle the static events raised by ContentManager, but of course you just substitute the ContentManager with the CmsManager and you are on your way.

    Let us know if you have any additional questions.

    Best wishes,
    Ivan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
4 posts, 0 answered