/// <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)); }
/// <summary> /// /// </summary> /// <typeparam name="Page"></typeparam> /// <param name="userControlPath"></param> /// <param name="id"></param> /// <returns></returns> public static UserControl LoadControl <Page>(string userControlPath, string id) where Page : System.Web.UI.Page, ISelfRenderingPage, new() { System.Web.UI.Page pageHolder = (System.Web.UI.Page) new Page(); ResourceManager rm = new ResourceManager(true); rm.RenderScripts = ResourceLocationType.None; rm.RenderStyles = ResourceLocationType.None; rm.IDMode = IDMode.Explicit; pageHolder.Controls.Add(rm); if (!userControlPath.StartsWith("~") && !userControlPath.StartsWith("/") && HttpContext.Current != null && HttpContext.Current.CurrentHandler is System.Web.UI.Page) { var dir = System.IO.Path.GetDirectoryName(HttpContext.Current.Request.CurrentExecutionFilePath).Replace("\\", "/"); userControlPath = dir + "/" + userControlPath; } id = id ?? BaseControl.GenerateId(); System.Web.UI.Control uc = pageHolder.LoadControl(userControlPath); uc.ID = id; return((UserControl)uc); }