Customizing Sitefinity’s dialogs

Customizing Sitefinity’s dialogs

Posted on July 21, 2014 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

Customizing Sitefinity’s built-in dialogs is a commonly requested scenario, so in the following blog post we will demonstrate how you can achieve this. For the purpose of this demo we are going to customize the CustomSortingDialog for Events module, located in Content->Events and choosing the Custom sorting… option in the upper right corner sorting drop-down menu.



All dialogs available in Sitefinity are resolved through Unity. This way you can easily replace any of the built in dialogs with custom ones that suffice for your application scenarios. 

Implementing the custom dialog class.

As usual, we need to first inherit from the base dialog class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telerik.Sitefinity.Web.UI.Backend.Elements;
 
namespace SitefinityWebApp
{
    public class CustomSortingDialogCustom : CustomSortingDialog
    {
    }
}

We are going to insert 2 more sorting criteria – EventStart and EventEnd. For the purpose of this we need to override the GetSortableFields() method and add the 2 additional options to the collection bound to the drop-down list.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
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;
        }
    }
}

Registering the dialog 

Our custom dialog is now ready and all that is left is to register it. You can do this in Global.asax on the Bootstrapper_Initialized event like so:

protected void Application_Start(object sender, EventArgs e)
        {
            Bootstrapper.Initialized += Bootstrapper_Initialized;
        }
 
        void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
        {           
            if (e.CommandName == "Bootstrapped")
            {                                                    ObjectFactory.Container.RegisterType(typeof(DialogBase), typeof(CustomSortingDialogCustom), typeof(CustomSortingDialog).Name, new HttpRequestLifetimeManager());
            }
        }

After building the project and running it in the browser our customized dialog is registered and the changes can be seen.


Pavel Benov

View all posts from Pavel Benov on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation