# Extend Sitefinity CMS's built-in dialogs

Sitefinity CMS enables you, as a developer, to customize built-in dialogs to better fit your specific requirements. All dialogs available in Sitefinity CMS are resolved through the [Unity](https://msdn.microsoft.com/en-us/library/ff647202.aspx) dependency injection container that you can use to easily replace the built-in dialog with a custom implementation.

This article describes how to customize the `CustomSortingDialog`dialog class of the *Events* module by adding two additional options for sorting events. You can use this approach with other content types as well.

> important **IMPORTANT**: The following procedure applies to Sitefinity Classic UI only.

To open the built-in *Custom sorting...* dialog for events:

1. Open Sitefinity CMS backend and navigate to *Content* » *Events*.
2. From the *Sort* dropdown menu upper right corner, select *Custom sorting…*

## Create the custom dialog class

To create the custom dialog class:

1. In Visual Studio, open the context menu of your Sitefinity project and click *Add* » *Class*.
2. Name the class file `CustomSortingDialogCustom.cs` and click *Add*.
3. Open the `CustomSortingDialogCustom.cs` and add the following code:

   ```C#
   using System.Collections.Generic;
   using Telerik.Sitefinity.Events.Model;
   using Telerik.Sitefinity.Web.UI.Backend.Elements;

   namespace SitefinityWebApp
   {
       public class CustomSortingDialogCustom : CustomSortingDialog
       {
           public override IList<KeyValuePair<string, string>> GetSortableFields()
           {
               var baseSortableFields = base.GetSortableFields();
               if (this.ContentType == typeof(Event))
               {
                   baseSortableFields.Add(new KeyValuePair<string, string>("EventStart", "Event Start"));
                   baseSortableFields.Add(new KeyValuePair<string, string>("EventEnd", "Event End"));
               }
               return baseSortableFields;
           }
       }
   }
   ```

   In the code above, you override the `GetSortableFields` method of the `CustomSortingDialog` class to add the following new sorting criteria:

   * `EventStart`
   * `EventEnd`

## Register the custom dialog class

After you implement the custom dialog class, you register the class, so that it is initialized upon application start of your Sitefinity CMS project. To do so:

1. In Visual Studio, open the context menu of your Sitefinity project and click *Add* » *New Item..*.
2. Select *Global Application Class*, name the class *Global.asax*.\
   Click *Add*.
3. Add the following code:

   ```C#
   using System;
   using Telerik.Sitefinity.Abstractions;
   using Telerik.Sitefinity.Web.UI;
   using Telerik.Sitefinity.Web.UI.Backend.Elements;

   namespace SitefinityWebApp
   {
       public class Global : System.Web.HttpApplication
       {
           protected void Application_Start(object sender, EventArgs e)
           {
               Bootstrapper.Bootstrapped += Bootstrapper_Bootstrapped;
           }

           private void Bootstrapper_Bootstrapped(object sender, EventArgs e)
           {
               ObjectFactory.Container.RegisterType(typeof(DialogBase), typeof(CustomSortingDialogCustom), typeof(CustomSortingDialog).Name, new HttpRequestLifetimeManager());
           }
       }
   }
   ```

In the code above, you use the `Bootstrapper `class to subscribe to the application start of your Sitefinity CMS project. In addition, you implement the handler that registers the new `CustomSortingDialogCustom` class.

As a result, you can use the new sorting criteria for events that you added to the built-in *Custom sorting...* dialog.
