Copied to clipboard

Flag this post as spam?

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


  • elspiko 133 posts 302 karma points
    Sep 21, 2009 @ 11:22
    elspiko
    0

    Simple way to hook into AfterPublish event using Custom DataType

    Hi all, hope we're doing ok on this "lovely" Monday morning!

    I'm wondering if theres an easy method to hook an existing custom datatype I've written in to a documents AfterPublish event?

    I've seen a couple of articles on this, and looking at them it would seem as though I'd have to rewrite the datatype more or less completly. I'm not totally against this, but if theres an easier way I'd much rather do that! :-)

     

    Thanks all

     

  • Aaron Powell 1708 posts 3046 karma points c-trib
    Sep 21, 2009 @ 11:40
    Aaron Powell
    0

    If you only want it on the page(s) which the Data Type is being used on you could put it into the ctor of the Data Type. But you'll need to make sure you don't register the event multiple times if the data type is used multiple times.

    You're really best to use ApplicationBase and register it that way, this will ensure that it's only registering the event handler once and regardless of whether the Data Type is being used.

  • Richard Soeteman 4052 posts 12925 karma points MVP 2x
    Sep 21, 2009 @ 11:42
    Richard Soeteman
    0

    Hi,

    Why do you want to insert a datatype when a document is published? I think you should either create a new datatype (which is not that painfull) or insert a value when publishing. Maybe I'm just not understanding what you are trying to achieve?

    Cheers,

    Richard

  • elspiko 133 posts 302 karma points
    Sep 21, 2009 @ 12:04
    elspiko
    0

    Richard,

    Crossed wires I think. Basically I've written a datatype which generates the TinyUrl for the document/page. At the moment it generates the value when a button is clicked, and will only generate the value when the page is published (therefore can access node.Url).

    Whilst this is possibly not a terrible method, I'd like to be able to automatically generate the TinyUrl value when the page is initally published. For subsequent times there would be a 'Regenerate' button which would request a new url for if the node name was changed for example.

     

    Slace,

    Can you give me an example what how I would register the event in the constructor? As the examples I've seen are Class Libraries that inherit solely off ApplicationBase rather than UserControls

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 21, 2009 @ 12:39
    Dirk De Grave
    0

    elspiko,

    I'm still confused as to why you're using a datatype for this? I'd rather build an event handler hooking into the save/publish of a document and update a document's property accordingly? It can be a property of type 'Label' to make sure editors cannot modify the contents.

    Here's a starter that may inspire...

     

    Hope this helps.

     

    Regards,

    /Dirk

     

Please Sign in or register to post replies

Write your reply to:

Draft