Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Global Events in K6 on Custom Table View modes: 
User avatar
Certified Developer 8
Certified Developer 8
richard - 1/17/2012 7:22:52 PM
   
Global Events in K6 on Custom Table
I wish to add a custom event handler for insert, update and delete on a custom table object in Kentico 6

I am a bit unsure how to use the ObjectEvents to register these event handlers.

This (http://devnet.kentico.com/Blogs/Martin-Hejtmanek/October-2011/Code-customization-in-Kentico-CMS-6.aspx) blog post has an example for UserInfo but not for custom tables.

Cheers

Richard

User avatar
Member
Member
kentico_michal - 1/18/2012 3:07:06 AM
   
RE:Global Events in K6 on Custom Table
Hello,

For custom tables, you need to use the events of the ObjectEvents class that are fired upon any object change:
- Insert - fired upon the insertion of a new object.
- Update - fired upon the update of the existing object.
- Delete - fired upon the object deletion.
- GetContent - Provides the additional object content to the search indexer.

ObjectEvents.Insert.After += new EventHandler<ObjectEventArgs>(Insert_After);

...

void Insert_After(object sender, ObjectEventArgs e)
{
// your custom code
}

Best regards,
Michal Legen

User avatar
Certified Developer 8
Certified Developer 8
richard - 1/18/2012 12:10:07 PM
   
RE:Global Events in K6 on Custom Table
Thanks Michal

Yes I figured that was the case. I then want to know which custom table is being altered.

So in the above example where it says "//your custom code" what would the code be that tells me what Custom table is being changed?

Cheers

Richard

User avatar
Member
Member
kentico_michal - 1/20/2012 5:17:50 AM
   
RE:Global Events in K6 on Custom Table
Hi Richard,

You can use the following code:

         
void Insert_After(object sender, ObjectEventArgs e)
{
CustomTableItem cti = e.Object as CustomTableItem;
if (cti != null)
{
string customTable = cti.CustomTableClassName;
}
}

Best regards,
Michal Legen

User avatar
Certified Developer 8
Certified Developer 8
richard - 1/21/2012 7:32:57 PM
   
RE:Global Events in K6 on Custom Table
Fantastic thanks Michal