public static Control LoadModuleControl(TemplateControl containerControl, ModuleInfo moduleConfiguration) { Control control = null; string extension = Path.GetExtension(moduleConfiguration.ModuleControl.ControlSrc.ToLower()); IModuleControlFactory controlFactory = null; switch (extension) { case ".ascx": controlFactory = new WebFormsModuleControlFactory(); break; case ".cshtml": case ".vbhtml": Type factoryType = Reflection.CreateType("DotNetNuke.Web.Razor.RazorModuleControlFactory"); if (factoryType != null) { controlFactory = Reflection.CreateObject(factoryType) as IModuleControlFactory; } break; default: // load from a typename in an assembly ( ie. server control) Type objType = Reflection.CreateType(moduleConfiguration.ModuleControl.ControlSrc); control = (containerControl.LoadControl(objType, null)); break; } if (controlFactory != null) { control = controlFactory.CreateModuleControl(containerControl, moduleConfiguration); } // set the control ID to the resource file name ( ie. controlname.ascx = controlname ) // this is necessary for the Localization in PageBase if (control != null) { control.ID = Path.GetFileNameWithoutExtension(moduleConfiguration.ModuleControl.ControlSrc); var moduleControl = control as IModuleControl; if (moduleControl != null) { moduleControl.ModuleContext.Configuration = moduleConfiguration; } } return(control); }
public static Control LoadModuleControl(TemplateControl containerControl, ModuleInfo moduleConfiguration) { Control control = null; string extension = Path.GetExtension(moduleConfiguration.ModuleControl.ControlSrc.ToLower()); IModuleControlFactory controlFactory = null; switch (extension) { case ".ascx": controlFactory = new WebFormsModuleControlFactory(); break; case ".cshtml": case ".vbhtml": Type factoryType = Reflection.CreateType("DotNetNuke.Web.Razor.RazorModuleControlFactory"); if (factoryType != null) { controlFactory = Reflection.CreateInstance(factoryType) as IModuleControlFactory; } break; default: // load from a typename in an assembly ( ie. server control) Type objType = Reflection.CreateType(moduleConfiguration.ModuleControl.ControlSrc); control = (containerControl.LoadControl(objType, null)); break; } if (controlFactory != null) { control = controlFactory.CreateModuleControl(containerControl, moduleConfiguration); } // set the control ID to the resource file name ( ie. controlname.ascx = controlname ) // this is necessary for the Localization in PageBase if (control != null) { control.ID = Path.GetFileNameWithoutExtension(moduleConfiguration.ModuleControl.ControlSrc); var moduleControl = control as IModuleControl; if (moduleControl != null) { moduleControl.ModuleContext.Configuration = moduleConfiguration; } } return control; }
private static IModuleControlFactory GetModuleControlFactory(string controlSrc) { string extension = Path.GetExtension(controlSrc.ToLowerInvariant()); IModuleControlFactory controlFactory = null; Type factoryType; switch (extension) { case ".ascx": controlFactory = new WebFormsModuleControlFactory(); break; case ".html": case ".htm": controlFactory = new Html5ModuleControlFactory(); break; case ".cshtml": case ".vbhtml": factoryType = Reflection.CreateType("DotNetNuke.Web.Razor.RazorModuleControlFactory"); if (factoryType != null) { controlFactory = Reflection.CreateObject(factoryType) as IModuleControlFactory; } break; case ".mvc": factoryType = Reflection.CreateType("DotNetNuke.Web.Mvc.MvcModuleControlFactory"); if (factoryType != null) { controlFactory = Reflection.CreateObject(factoryType) as IModuleControlFactory; } break; default: controlFactory = new ReflectedModuleControlFactory(); break; } return(controlFactory); }