Temporarily disable Sitecore client notifications to suppress unwanted new-item redirects

The default behavior, when a user kicks off any action in the Sitecore client which adds a new item, is that the client redirects to the newly created item. In some (many) cases this may be desirable, but in others it is an unwanted side effect.

In order to suppress this behavior, two approaches may be helpful. One sometimes recommended is to suppress all events while creating the new item, but this should be done with caution depending on the environment. To do this enclose the item-creation code in a using statement like this one:

using (new Sitecore.Data.Events.EventDisabler()
{
// item creation code here...
}

Even better, and an approach which should be sufficient by itself, is to suppress client notifications during the item creation, like so:

Sitecore.Client.Site.Notifications.Disabled = true;
// item creation code here...
Sitecore.Client.Site.Notifications.Disabled = false;

To be safe, be sure to re-enable client notifications in the finally of a try-catch block. Also, depending on the Sitecore version, bucketable items may need a special tweak to suppress notifications as well.

2 comments

  1. Jan Löwgren · May 14, 2015

    I’m curious as to what kind of scenario you have in mind here. Is the user performing some custom command to begin with or are you referring to bult-in commands like inserting items regularly?

    Liked by 1 person

    • Jeff Varszegi · May 14, 2015

      If I recall correctly, I discovered this and posted the tip in the middle of developing a custom field which would often be mapped, for its item-choosing root, to an auto-found-or-created place in the media library. (I may write a separate post about the approach we used for that development, but it involved a highly structured branch template that would be used as the basis for a new logical website, with so many places for choosing and adding media items that avoiding a “wild west” atmosphere in the media library implied some sort of repeatable structure there too.) So yes, a user interaction through the content editor that might create an item.

      Like

Leave a comment