From f6eb9c77a9f2b829a75ee439c474a0bc952943da Mon Sep 17 00:00:00 2001 From: sgay Date: Thu, 14 Jul 2011 06:54:14 -0200 Subject: [PATCH] Add RenderEvent to Macro control [#30362] --- .../umbraco/templateControls/Macro.cs | 44 +++++++++++++++++-- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/umbraco/presentation/umbraco/templateControls/Macro.cs b/umbraco/presentation/umbraco/templateControls/Macro.cs index 095dad1b59..ea44f42c58 100644 --- a/umbraco/presentation/umbraco/templateControls/Macro.cs +++ b/umbraco/presentation/umbraco/templateControls/Macro.cs @@ -79,17 +79,54 @@ namespace umbraco.presentation.templateControls } } - /// + [Bindable(true)] + [Category("Umbraco")] + [DefaultValue(RenderEvents.Init)] + [Localizable(true)] + public RenderEvents RenderEvent + { + get + { + RenderEvents renderEvent = RenderEvents.Init; + if (ViewState["RenderEvent"] != null) + renderEvent = (RenderEvents)ViewState["RenderEvent"]; + return renderEvent; + } + set + { + ViewState["RenderEvent"] = value; + } + } + + // Indicates where to run EnsureChildControls and effectively render the macro + public enum RenderEvents + { + Init, + PreRender, + Render + } + + /// /// Raises the event. /// /// An object that contains the event data. protected override void OnInit(EventArgs e) { base.OnInit(e); - // Make sure child controls are in place to receive postback data. - EnsureChildControls(); + // Create child controls when told to - this is the default + if (this.RenderEvent == RenderEvents.Init) + EnsureChildControls(); } + // Create child controls when told to - new option to render at PreRender + protected override void OnPreRender(EventArgs e) + { + base.OnPreRender(e); + + if (this.RenderEvent == RenderEvents.PreRender) + EnsureChildControls(); + } + /// /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering. /// @@ -151,6 +188,7 @@ namespace umbraco.presentation.templateControls /// The object that receives the control content. protected override void Render(HtmlTextWriter writer) { + // Create child controls when told to - do it here anyway as it has to be done EnsureChildControls(); bool isDebug = GlobalSettings.DebugMode && (helper.Request("umbdebugshowtrace") != "" || helper.Request("umbdebug") != "");