Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom Maton 387 posts 659 karma points
    Aug 02, 2010 @ 18:08
    Tom Maton
    0

    AfterDelete & AfterSendToTrash dont seem to be working

    Hi All,

    I'm trying to fire some an event handler when the editor deletes a page but I cant seem to capture that event.

    I have tried

    • AfterDelete
    • BeforeDelete
    • AfterMoveToTrash
    • BeforeMoveToTrash

    And nothing seems to work, all I get is that I'm not able to delete and pages/nodes from the content tree.

    I'm using Umbraco 4.0.3

    Thanks

    Tom

     

  • Darren Ferguson 1022 posts 3258 karma points MVP c-trib
    Aug 02, 2010 @ 22:18
    Darren Ferguson
    0

    There are certain events that don't fire at all.

    If you are convinced that one isn't working then I'd file a bug.

    I've fallen into the trap on a few occasions of not having my event handling class marked public - in which case it won't work.

     

     

  • Richard Soeteman 3875 posts 12037 karma points MVP
    Aug 03, 2010 @ 08:56
    Richard Soeteman
    0

    Hi Tom,

    I've used these events with 4.0.3. Please provide some sourcecode.

    Cheers,

    Richard

  • Tom Maton 387 posts 659 karma points
    Aug 03, 2010 @ 10:14
    Tom Maton
    0

    Hi Richard,

    This is part of my code.

    Document.AfterDelete += new Document.DeleteEventHandler(Document_AfterDelete);

    void Document_AfterDelete(Document sender, DeleteEventArgs e)
    {
    //Business logic here
    }

    Darren,

    I've also tried making it public but still no difference :(

    Thanks

    Tom

  • Darren Ferguson 1022 posts 3258 karma points MVP c-trib
    Aug 03, 2010 @ 10:30
    Darren Ferguson
    0

    Can you post the whole class?

    What isn't working? Have you tried putting some logging in to see whether your event is fired but the business logic is failing?

     

  • Richard Soeteman 3875 posts 12037 karma points MVP
    Aug 03, 2010 @ 10:40
    Richard Soeteman
    0

    As Darren mentioned can you provide the whole class, I think you don't derive from ApplicationBase.

    Cheers,

    Richard

  • Tom Maton 387 posts 659 karma points
    Aug 03, 2010 @ 10:53
    Tom Maton
    0

    Hi Guys

    This is my whole class:

    )

    public class DataManager : ApplicationBase
        {
            #region Public Members
            public DataManager()
            {
                Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish);
                Document.AfterDelete += new Document.DeleteEventHandler(Document_AfterDelete);
            }
                 
            void Document_AfterDelete(Document sender, DeleteEventArgs e)
            {
                XML.XMLManager.DeleteNodeData(sender.UniqueId,DataManager.FileName(sender.Parent.Text));
            }

            void Document_AfterPublish(Document sender, PublishEventArgs e)
            {
                GetNodeData(sender);
            }

            public static string FileName(string schoolName)
            {
                schoolName = String.Concat(Regex.Replace(schoolName.ToLower(), @"\s", String.Empty), ".xml").Replace("acs", String.Empty);
                return schoolName;
            }

            #endregion

            #region Private Members
            private void GetNodeData(Document DocumentContent)
            {
               
                Data NodeValues = new Data(DocumentContent);           
               
            }

           
            #endregion
        }

    The AfterPublish method is working no problem and fires everytime.

    Thanks

    Tom

  • Richard Soeteman 3875 posts 12037 karma points MVP
    Aug 03, 2010 @ 10:56
    Richard Soeteman
    0

    Did you already try to set a breakpoint on the AfterDelete event handler? Also this event gets fired when you empty the trash not when you delet the item in Umbraco.

    Cheers,

    Richard

  • Darren Ferguson 1022 posts 3258 karma points MVP c-trib
    Aug 03, 2010 @ 10:56
    Darren Ferguson
    0

    I think you want the AfterMoveToTrash event. I don't think afterdelete is fired until the recycle bin is emptied.

  • Tom Maton 387 posts 659 karma points
    Aug 03, 2010 @ 11:43
    Tom Maton
    0

    I've tried the AfterMoveToTrash event and in debug mode its not getting to the breakpoint and the page is not even deleteable it just stays in the tree.

    Thanks

    Tom

  • Darren Ferguson 1022 posts 3258 karma points MVP c-trib
    Aug 03, 2010 @ 11:46
    Darren Ferguson
    0

    Post your class again and i'll run it locally. I have 4.0.3 installed.

     

  • Tom Maton 387 posts 659 karma points
    Aug 03, 2010 @ 12:22
    Tom Maton
    0

    Hi Darren,

    This is the entire class.


    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Text.RegularExpressions;

    using umbraco.BusinessLogic;
    using umbraco.cms.businesslogic;
    using umbraco.cms.businesslogic.web;
    using umbraco.presentation.nodeFactory;


    namespace Precedent.ACS.Data
    {
        public class DataManager : ApplicationBase
        {
            #region Public Members
            public DataManager()
            {
                Document.AfterPublish += new Document.PublishEventHandler(Document_AfterPublish);
                //Document.AfterDelete += new Document.DeleteEventHandler(Document_AfterDelete);
                Document.AfterMoveToTrash += new Document.MoveToTrashEventHandler(Document_AfterMoveToTrash);
            }

            void Document_AfterMoveToTrash(Document sender, MoveToTrashEventArgs e)
            {           
    //Business logic
            }
                 
            public void Document_AfterDelete(Document sender, DeleteEventArgs e)
            {
                //Business logic
            }

            void Document_AfterPublish(Document sender, PublishEventArgs e)
            {
                //Business logic
            }

           
            #endregion       
        }
    }

    Thanks

    Tom

  • Darren Ferguson 1022 posts 3258 karma points MVP c-trib
    Aug 03, 2010 @ 12:57
    Darren Ferguson
    1

    The issue isn't the code.

    I copied it as is and I can hit the breakpoint:

  • Tom Maton 387 posts 659 karma points
    Aug 03, 2010 @ 13:38
    Tom Maton
    0

    hmm...

    Stupid question but how are you deleting the page from the tree to get to that breakpoint?

    Tom

  • Darren Ferguson 1022 posts 3258 karma points MVP c-trib
    Aug 03, 2010 @ 14:03
    Darren Ferguson
    0

    right click. then delete.

     

  • Tom Maton 387 posts 659 karma points
    Aug 03, 2010 @ 15:32
    Tom Maton
    0

    Right this is now working, just deleted the AfterMoveToTrash and now it works.

    Thanks for looking into this Darren much appreciated.

    Tom

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies