Custom table | Global Event | Create | Update | Delete

pankaj saxena asked on February 15, 2023 08:02

Hi Team,

Can anyone suggest me to write the global event for Custom table. I find in the Kentico documentation so its all about the module.

So I need for the global event for custom table.

Like for Module write:

[assembly: RegisterModule(typeof(WidgetList))] namespace CMSApp.Old_App_Code.GlobalEvents { public class WidgetList : Module { public WidgetList() : base("WidgetList") { }

    protected override void OnInit()
    {
        base.OnInit();
        WidgetListInfo.TYPEINFO.Events.Insert.Before += WidgetList_Insert_Before;
    }

    private void WidgetList_Insert_Before(object sender, ObjectEventArgs e)
    {
       ....
    }        
}

}

Recent Answers


Liam Goldfinch answered on February 15, 2023 09:55

You will need to use CustomTableItemEvents I believe.

Should be something like this:

protected override void OnInit()
{
    base.OnInit();
    CustomTableItemEvents.Insert.Before += Insert_Before;
}

private void Insert_Before(object sender, CustomTableItemEventArgs e)
{
   ....
}
0 votesVote for this answer Mark as a Correct answer

pankaj saxena answered on February 15, 2023 10:00

Hi Liam Goldfinch,

I just want to know like if we write the global event for module we register first then we inherit the class Module like: [assembly: RegisterModule(typeof(WidgetList))] public class WidgetList : Module .

So same we do for the custom table can you please confirm or you provide any document or example where the global event written for custom table.

0 votesVote for this answer Mark as a Correct answer

Liam Goldfinch answered on February 15, 2023 10:20 (last edited on February 15, 2023 10:21)

I would recommend reading this.

Essentially if you want to modify how the behaviour of Kentico works, e.g. setting up global events, then you can use a module class to initialise the code.

So yes you can do the same, it would look something like this:

using CMS;
using CMS.Core;
using CMS.DataEngine;

[assembly: RegisterModule(typeof(ExampleModule))]

public class ExampleModule : Module
{    
    public ExampleModule() : base("ExampleModule")
    {
    }

    protected override void OnInit()
    {
        base.OnInit();
        CustomTableItemEvents.Insert.Before += Insert_Before;
    }

    private void Insert_Before(object sender, CustomTableItemEventArgs e)
    {
       ....
    }
 }
0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on February 15, 2023 13:59

This global event is created in the CMS project not in the MVC project. Read the documentation Liam provided and it will get you what you need.

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.