/// <summary> /// Load server side module control with dynamic position of control and dynamic Control Path /// </summary> /// <param name="ModuleName">ModuleName</param> /// <param name="ControlTypeName">Name of Control Type</param> /// <param name="UserModuleID">UserModuleID</param> /// <param name="IsAtTop">Set true if control need to be set in top of existing module in the page</param> public void ModuleLoaderWithDynamicControl(string ModuleName, string ControlTypeName, string UserModuleID, bool IsAtTop) { try { string ControlSrcPath = ""; ModuleLoaderInfo ControlSrc = new ModuleLoaderInfo(); ModuleLoaderController objController = new ModuleLoaderController(); int controlType = ModuleControlType(ControlTypeName); List<ModuleLoaderInfo> objControlList = objController.GetControlSrcByModuleName(ModuleName); if (objControlList.Count > 0) { foreach (var item in objControlList) { ControlSrc = objControlList.Single(x => x.ControlType == controlType); ControlSrcPath = ControlSrc.ControlSrc; } PlaceHolder ph = new PlaceHolder(); if (IsAtTop) this.Controls.AddAt(1, ph); else this.Controls.Add(ph); SageUserControl userControl = (SageUserControl)Page.LoadControl(ControlSrcPath); userControl.SageUserModuleID = SageUserModuleID; ph.Controls.Add(userControl); } else { return; } } catch (Exception ex) { throw ex; } }
/// <summary> /// Load client side module control with dynamic Control Path and Returns Loaded Control Code /// </summary> /// <param name="ModuleName">ModuleName</param> /// <param name="ControlTypeName">Name of Control Type</param> /// <param name="UserModuleID">UserModuleID</param> /// <returns>Control source code</returns> public string ModuleLoaderForJsWithDynamicControl(string ModuleName, string ControlTypeName, string UserModuleID) { try { string ControlSrcPath = ""; string controlCode = ""; ModuleLoaderInfo ControlSrc = new ModuleLoaderInfo(); ModuleLoaderController objController = new ModuleLoaderController(); int controlType = ModuleControlType(ControlTypeName); if (ModuleName != string.Empty) { List<ModuleLoaderInfo> objControlList = objController.GetControlSrcByModuleName(ModuleName); if (objControlList != null) { foreach (var item in objControlList) { ControlSrc = objControlList.Single(x => x.ControlType == controlType); ControlSrcPath = ControlSrc.ControlSrc; } Page ucPage = new Page(); Page virPage = new Page(); SageUserControl userControl = (SageUserControl)ucPage.LoadControl(ControlSrcPath); userControl.EnableViewState = true; userControl.SageUserModuleID = UserModuleID.ToString(); virPage.Controls.Add(userControl); StringWriter writer = new StringWriter(); HttpContext.Current.Server.Execute(virPage, writer, true); controlCode = writer.ToString(); } else { controlCode = "Control Not found"; } } else { controlCode = "Module Name empty"; } return controlCode; } catch (Exception ex) { throw ex; } }