---
title: Handling object events
related:
  - https://docs.kentico.com/k10/custom-development/handling-global-events.md
  - https://docs.kentico.com/k10/custom-development/handling-global-events/reference-global-system-events.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

Objects include all data structures used within Kentico, for example user accounts, forums, page templates, search indexes, or setting keys. By handling the events that occur during the life cycle of objects, you can add custom functionality to almost any part of the system. In the API, objects are represented by _Info_ classes.

Use the following classes to access the object events:

- **ObjectEvents** - events triggered for all object types
- **Info.TYPEINFO.Events** - events triggered only for a specific object type, for example: _UserInfo.TYPEINFO.Events_

See the [Global event reference](https://docs.kentico.com/k10/custom-development/handling-global-events/reference-global-system-events.md) for information about the available events.

> **Info:** **Note**: Within the context of event handling, objects do NOT include pages in the website content tree. Use the **DocumentEvents** class to assign handlers to events that the system triggers for pages.

## Example

The following example demonstrates how to use event handlers to customize the behavior of a specific type of object.

The sample code extends the functionality of [forum groups](https://docs.kentico.com/k10/community-features/forums.md) by creating a handler for the **Insert.After** event of the **ForumGroupInfo** object type. This event occurs whenever a forum group is created. The custom logic automatically adds an initial child forum for every new forum group.

1. Open your Kentico project in Visual Studio (using the **WebSite.sln** or **WebApp.sln** file).
2. Create a [custom module class](https://docs.kentico.com/k10/custom-development/creating-custom-modules/initializing-modules-to-run-custom-code.md).
   - Either add the class into a custom project within the Kentico solution (recommended) or directly into the Kentico web project (into a custom folder under the **CMSApp** project for _web application_ installations, into the **App\_Code** folder for _web site_ installations).
3. Override the module's **OnInit** method and assign a handler method to the **ForumGroupInfo.TYPEINFO.Events.Insert.After** event.

```csharp

using CMS;
using CMS.DataEngine;
using CMS.Forums;
using CMS.Helpers;

// Registers the custom module into the system
[assembly: RegisterModule(typeof(CustomForumModule))]

public class CustomForumModule : Module
{
    // Module class constructor, the system registers the module under the name "CustomForums"
    public CustomForumModule()
        : base("CustomForums")
    {
    }

    // Contains initialization code that is executed when the application starts
    protected override void OnInit()
    {
        base.OnInit();

        // Assigns a handler to the Insert.After event for the ForumGroupInfo object type
        // This event occurs after the creation of every new forum group
        ForumGroupInfo.TYPEINFO.Events.Insert.After += ForumGroup_InsertAfterEventHandler;
    }

    /// <summary>
    /// Automatically creates a child forum for new forum groups
    /// </summary>
    private void ForumGroup_InsertAfterEventHandler(object sender, ObjectEventArgs e)
    {
        // Checks that the forum group was successfully created
        if (e.Object != null)
        {
            // Gets an info object representing the new forum group
            ForumGroupInfo forumGroup = (ForumGroupInfo)e.Object;

            // Creates the child forum object
            ForumInfo newForum = new ForumInfo()
            {
                // Sets the child forum's properties
                ForumDisplayName = forumGroup.GroupDisplayName + " - General",
                ForumName = forumGroup.GroupName + "_General",
                ForumGroupID = forumGroup.GroupID,
                ForumSiteID = forumGroup.GroupSiteID,

                ForumOpen = true,
                ForumModerated = false,
                AllowAccess = SecurityAccessEnum.AllUsers,
                ForumThreads = 0,
                ForumPosts = 0
            };

            // Saves the child forum to the database
            ForumInfoProvider.SetForumInfo(newForum);
        }
    }
}

```

To try out the functionality of the custom event handler, create a new forum group on any website:

1. Open the **Forums** application.
2. Click **New forum group**.
3. Type a name into the **Group display name** field of the new forum group.
4. Click **Save**.

The system automatically creates a child forum named after the forum group (with a _" - General"_ suffix).
