Search code examples
savesitecorecomponentssublayout

Sitecore Auto-Save If Sublayout Added on the Page


Is there anyway to make auto-save once I added a sublayout component?

I created one sublayout and if I add it on the page in page editor, it doesn't appear on that time. By saving the item, it appears on the page editor.

So, I'd like to make if sublayouts are added on the page, then make the page automatic save.

Is it possible?

===== Update =====

This is the end of CreateNewDatasource Method and it updates Rendering Layout field.

//set datasource, save and close
myItem.Editing.BeginEdit();
myDataSourceItem = myItem.Add(newName, template);
rd.Datasource = myDataSourceItem.ID.ToString();
myItem[Sitecore.FieldIDs.LayoutField] = ld.ToXml();
myItem.Editing.EndEdit();
myItem.Editing.AcceptChanges();

return myDataSourceItem;

Solution

  • I'm not sure what the exact issue is with the way you have the control coded currently, I assume is to do with Sitecore control lifescycle so would need more in depth investigation. In any case, I suggest you re-think and implement using a more Sitecore friendly process.

    Instead you should Prompt the User to Select/Create Datasource Item when inserting Rendering via Page Editor. The user can then either select an existing item or create a new one. The item will automatically be set as the datasource of your control and you will be able to immediately start editing in the Page Editor without having to save first.