/// <summary>
        ///
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public virtual string Build(UserControlRendrerConfig config)
        {
            string      id = config.UserControlId ?? BaseControl.GenerateId();
            UserControl uc = UserControlRenderer.LoadControl(config.UserControlPath, id);

            uc.ClientIDMode = config.UserControlClientIDMode;
            Page pageHolder = uc.Page;

            BaseControl controlToRender = null;

            if (config.ControlIdToRender.IsEmpty() && !config.SingleControl)
            {
                Container ct = new Container {
                    ID = id + "_ct", IDMode = IDMode.Static
                };
                pageHolder.Controls.Add(ct);
                ct.ContentControls.Add(uc);
                controlToRender = ct;
            }
            else
            {
                pageHolder.Controls.Add(uc);
                BaseControl c;

                if (config.SingleControl)
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl <BaseControl>(uc);
                }
                else
                {
                    c = Ext.Net.Utilities.ControlUtils.FindControl <BaseControl>(pageHolder, config.ControlIdToRender);
                }

                if (c == null)
                {
                    if (config.SingleControl)
                    {
                        throw new Exception("Cannot find the Ext.Net control in the view");
                    }
                    else
                    {
                        throw new Exception("Cannot find the control with ID=" + config.ControlIdToRender);
                    }
                }

                controlToRender = c;

                if (!controlToRender.HasOwnIDMode)
                {
                    controlToRender.IDMode = IDMode.Static;
                }
            }

            config.OnBeforeRender(new ComponentAddedEventArgs(controlToRender));

            return(config.Index.HasValue ? controlToRender.ToScript(config.Mode, config.Element, config.Index.Value, true) : controlToRender.ToScript(config.Mode, config.Element, true));
        }
        public static void Render(UserControlRendrerConfig config)
        {
            ResourceManager rm = ResourceManager.GetInstance(HttpContext.Current);

            var script = UserControlRenderer.ToScript(config);

            if (HttpContext.Current.CurrentHandler is Page && rm != null)
            {
                rm.AddScript(script);
            }
            else
            {
                new DirectResponse(script).Return();
            }
        }
 public static void Render(UserControlRendrerConfig config)
 {
     UserControlRenderer.Render(config, false);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="userControlPath"></param>
 /// <param name="controlIdToRender"></param>
 /// <param name="mode"></param>
 /// <param name="element"></param>
 /// <param name="index"></param>
 /// <returns></returns>
 public static string ToScript(UserControlRendrerConfig config)
 {
     return(new UserControlRenderer().Build(config));
 }