N2.Web.UI.WebControls.ItemEditorList.CreateButton C# (CSharp) Method

CreateButton() private method

private CreateButton ( Control container, N2.Definitions.TemplateDefinition template ) : LinkButton
container System.Web.UI.Control
template N2.Definitions.TemplateDefinition
return System.Web.UI.WebControls.LinkButton
        private LinkButton CreateButton(Control container, TemplateDefinition template)
        {
            var button = new LinkButton
            {
				ID = "iel" + ID + "_" + template.Definition.GetDiscriminatorWithTemplateKey().Replace('/', '_'),
				Text = string.IsNullOrEmpty(template.Definition.IconUrl)
                    ? string.Format("<b class='{0}'></b> {1}", template.Definition.IconClass, template.Definition.Title)
                    : string.Format("<img src='{0}' alt='ico'/>{1}", template.Definition.IconUrl, template.Definition.Title),
                ToolTip = template.Definition.ToolTip,
                CausesValidation = false,
                CssClass = "addButton"
            };
            button.Command += (s, a) =>
            {
				var parentEditor = ItemUtility.FindInParents<ItemEditor>(Parent);
				var parentVersion = parentEditor.GetAutosaveVersion()
					?? ParentItem;

				var path = EnsureDraft(parentVersion);

				UpdateItemFromTopEditor(path);

				ContentItem item = CreateItem(template.Definition);
				item.AddTo(path.CurrentItem, ZoneName);
				Utility.UpdateSortOrder(path.CurrentItem.Children).ToList();

				if (path.CurrentPage.ID != 0 || path.CurrentPage.VersionOf.HasValue)
				{
					var cvr = Engine.Resolve<ContentVersionRepository>();
					cvr.Save(path.CurrentPage);

					RedirectToVersionOfSelf(path.CurrentPage);
				}
				else
				{
					Engine.Persister.SaveRecursive(path.CurrentPage);
					RedirectToVersionOfSelf(path.CurrentPage);
				}
			};
            container.Controls.Add(button);
            return button;
        }