Dynamically Load a Module

Last post 05-15-2005 3:27 PM by fpstevens. 10 replies.

Sort Posts:

  • Dynamically Load a Module

    04-01-2005, 2:55 AM
    • Member
      20 point Member
    • azgrimedog1
    • Member since 04-01-2005, 7:47 AM
    • Posts 4

    Is there anyway to Load a Module dynamically in code?  I have been trying to find it in the core objects but just not seeing it.  I want to try and load a Module within another Module.  Can someone help with this or at least point me in the right direction as to how I could so this?  I am working with version 3.012.

    thanks!

  • Re: Dynamically Load a Module

    04-01-2005, 3:01 AM

    If you've got as far as loading a moduleinfo object using the DotNetNuke.Entities.Modules.ModuleController class, it goes something like this:  (this code assumes you've already loaded a module's info into mobjShadowModuleInfo)

    Dim shadowModule As DotNetNuke.Entities.Modules.PortalModuleBase

    shadowModule = CType(Page.LoadControl("~/" & mobjShadowModuleInfo.ControlSrc), DotNetNuke.Entities.Modules.PortalModuleBase)

    shadowModule.ModuleConfiguration = New DotNetNuke.Entities.Modules.ModuleInfo

    Me.Controls.Add(shadowModule)

  • Re: Dynamically Load a Module

    04-01-2005, 10:50 AM
    • Member
      20 point Member
    • azgrimedog1
    • Member since 04-01-2005, 7:47 AM
    • Posts 4
    I had already done something similar but I should have been more clear.  I was using the LoadControl method, however I can't seem to get the Container and Edit Menu, etc to Load within the Module when I do this.  Is there something I am missing.  I would like a user to edit the module settings of the dynamic module within this "Parent" Module I am creating...  Right now I just get the control to load but there is nothing else to do.  Right now its like I would have to have these modules on a hidden tab for administration purposes and then I would just load that hidden tab instance into my Parent Module.  Thats probably a solution but I would prefer to not do it this way, any suggestions?
  • Re: Dynamically Load a Module

    04-01-2005, 11:38 AM
    • Star
      8,505 point Star
    • christoc
    • Member since 01-03-2003, 7:49 AM
    • St. Louis, Missouri
    • Posts 1,560

    I'm not sure if that'll be possible out of the box.

    You'd need to do a "load action" on each of these dynamic modules you load, to load up the menu items for those modules, but linking those menu items to the "load action" list from the parent module may not be possible, if it would be I think you'd have to have those actions defined for the "parent" module in the module definitions file.

    If I get some time this weekend i'll try to play with that, but from what I understand right now I don't think it'll work.

  • Geeked [8-|] Re: Dynamically Load a Module

    04-01-2005, 12:22 PM
    • Member
      615 point Member
    • fpstevens
    • Member since 02-18-2005, 5:10 AM
    • Johannesburg - South Africa
    • Posts 123

    I Use the following method, I have a "Main" Control which is responsible for loading each of the other ascx files and displaying them, its an empty .ascx file with only the following code in it:

    public abstract class Configurator : PortalModuleBase, IActionable, IPortable, ISearchable
    {
          string _DefaultPage = "~/DeskTopModules/Novasoft-Configurator/Main.ascx";
          ....
          
    private void Page_Load(object sender, System.EventArgs e)
         
    {
             
    try 
            {
                
    if(Request.Params["ControlPath"] != null
                   {
                      
       string ControlPath = Request.Params["ControlPath"];
                         _DefaultPage = "~/DeskTopModules/Novasoft-Configurator/" + ControlPath;
                   }
                PortalModuleBase objModule = (PortalModuleBase)
    this.Page.LoadControl(_DefaultPage);
                
    if(objModule != null)
                   {
                      objModule.ModuleConfiguration =
    this.ModuleConfiguration;
                      Controls.Add(objModule);
                   }
             } 
             
    catch (Exception exc) 
             {
                Exceptions.ProcessModuleLoadException(
    this, exc);
             }
         }

    ....

    I Pass the name of the .ascx file i want to load in the url as ControlPath=****.ascx

    I Cant take credit for this code though, i got it from another dnn module, i just cant remember which one right now.

    "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction." --Albert Einstein
  • Re: Dynamically Load a Module

    04-01-2005, 12:55 PM
    • Star
      8,505 point Star
    • christoc
    • Member since 01-03-2003, 7:49 AM
    • St. Louis, Missouri
    • Posts 1,560
    fpstevens, does that bring over the Module Actions when you load the child control?
  • Re: Dynamically Load a Module

    04-01-2005, 1:05 PM
    • Member
      20 point Member
    • azgrimedog1
    • Member since 04-01-2005, 7:47 AM
    • Posts 4
    No it doesn't, I have already tried it and after this at this code its not doing much more than the other code example which is doing a simple LoadControl of the source ascx file.  The ModuleConfiguration was the only difference that I tried to implement and it do any different...
  • Re: Dynamically Load a Module

    04-01-2005, 11:13 PM
    • Member
      20 point Member
    • azgrimedog1
    • Member since 04-01-2005, 7:47 AM
    • Posts 4

    I am now trying to accomplish this using the InjectModule method of the Skin Class however when I try to use the InjectModule directly it error while checking a Request.QueryString because the Request object is null when I create a new Skin Class when calling the InjectModule class.  Can someone lead me in the right direction on using the InjectModule method.

    thanks

  • Re: Dynamically Load a Module

    04-02-2005, 5:00 PM
    • Participant
      1,375 point Participant
    • rickhodder
    • Member since 04-04-2003, 2:12 AM
    • Posts 276

    Hi,

    I was struggling with this too, and had to put it on the back burner for a while.

    You may want to take a look at default.aspx to see how the skin class is loaded using a placeholder. Since the placeholder is already on a page, it has access to the Request, Response, etc. of the page it is on.

    Rick

  • Re: Dynamically Load a Module

    05-14-2005, 9:09 PM
    • Member
      25 point Member
    • steph_unik
    • Member since 09-04-2003, 8:01 AM
    • Posts 5

    I try something similar without any success. I created a page containing two module, the first one located on the left pane contain a treeview control.  The second module is acting as a "Master" PlaceHolder for other modules.  At this point when a selection is made from the treeview a "RaiseEvent ModuleCommunication" is executed.  The second module located in the center pane is receiving information about the usercontrol to load since "IModuleListener.OnModuleCommunication" event.  Once the new control is loaded into a place Holder Control with LoadControl method, a click on buttons inside the "slave" module does'nt allow me to reply information to the master module.  I try this way http://blogs.wdevs.com/am/articles/532.aspx. I saw your post and i think maybe the way you display dynamicly your module can help me to fix this big issue.  I'm newbie with dnn3 your help will be really appreciated.

    Thanks you,

    Stephane :)

  • Re: Dynamically Load a Module

    05-15-2005, 3:27 PM
    • Member
      615 point Member
    • fpstevens
    • Member since 02-18-2005, 5:10 AM
    • Johannesburg - South Africa
    • Posts 123

    I'll help where I can, Mail or PM me if you need me to look at your code, I can't promise anything since I'm still learning DNN myself, but I will help where I can

    Paul Stevens

    "Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction." --Albert Einstein
Page 1 of 1 (11 items)