U4-1764 - ContentType save event is fired 3 times

Created by Joao Pinto 22 Feb 2013, 09:02:58 Updated by Morten Christensen 25 Feb 2013, 15:36:32

Relates to: U4-1714

using System.Web; using umbraco.interfaces; using Umbraco.Core.Models; using Umbraco.Core.Services;

public class MultiLanguageModule : IApplicationStartupHandler{ public MultiLanguageModule() { ContentTypeService.SavedContentType += Test; }

private void Test(IContentTypeService sender, Umbraco.Core.Events.SaveEventArgs e)
    HttpContext.Current.Response.Write("TEST"); //will print TESTTESTTEST, while it should be printed only once.



Andy Butland 22 Feb 2013, 10:31:13

I was having a look at this previously and can detail why it's happening - there are 3 calls to the content type save event.

  1. ContentTypeControlNew.ascx.cs > save_click
  2. EditNodeTypeNew.ascx.cs > OnBubbleEvent - call before setting properties
  3. EditNodeTypeNew.ascx.cs > OnBubbleEvent - call after setting properties

All 3 call the depreciated DocumentType.Save() which then calls the new API which files the events.

It looks to me that currently due to the way the UI for editing document types is constructed across two user controls (with part shared between the media type and content type - ContentTypeControlNew.ascx - and part for the content type only fields - EditNodeTypeNew.ascx) there does currently need to be 2 calls to the save event to make sure both sets of properties are saved. However I think the first call in EditNodeTypeNew.ascx.cs is unnecessary and could be removed.

Morten Christensen 22 Feb 2013, 13:07:43

Thanks for the heads up Andy! I'm currently working on ContentTypeControlNew.ascx.cs and give it a good cleanup, so it better utilize the new API and not so much legacy. Its needed for a few tasks I'm working on, but not sure how much we can do about the save events, as it'll be a breaking change if we just remove them. But will give some thought as to how we can improve this.

Andy Butland 22 Feb 2013, 17:07:27

No problem. Just to clarify though I think the events are fine - they fire where they should on save. Issue though is save is called 3 times so they fire 3 times. If you can reduce that to once then the issue would be solved. Maybe combining into a single user control would allow that, though at the expense of not reusing the control for editing media types.

Morten Christensen 25 Feb 2013, 15:36:32

I have now reduced the number of times a DocumentType is saved from 3 to 1 by cleaning up the code and adding a callback to the ContentTypeControlNew control, so the allowed templates are saved as part of the "normal" DocumentType save (click) event.

Priority: Normal

Type: Bug

State: Fixed

Assignee: Morten Christensen

Difficulty: Normal

Category: Extensibility

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.0.0

Due in version: 6.0.1


Story Points: