I need to be able to load modules dynamically. I couldn't seem to find a function that would let me do this in the DotNetNuke source (and AddNewModule is protected) so I created a helper class to call the function for me. The issue is that when I call AddDynamicModule, the Request object isn't set. I believe this is because I'm creating the DynamicModuleLoader object after the request object is set, but I'm not positive. So the end result is I get into the AddNewModule in ControlPanelBase and I get an exception on this line 178( If Request.IsAuthenticated Then) because Request is null. I really don't want to have to modify any DotNetNuke source if I can help it (it makes upgrades a pain.) Thank you for your help!
I have created a new class called DynamicModuleLoader that inherits ControlPanelBase. Here is the code:
Public Class DynamicModuleLoader
Inherits ControlPanelBase
Public Sub AddDynamicModule(ByVal title As String, ByVal desktopModuleId As Integer, ByVal paneName As String, ByVal position As Integer, ByVal align As String)
MyBase.AddNewModule(title, desktopModuleId, paneName, position, ViewPermissionType.View, align)
End Sub
End Class
And here is the code in my module:
public partial class View : DotNetNuke.Entities.Modules.PortalModuleBase
{
public static DynamicModuleLoader sHelper = new DynamicModuleLoader();
protected void tvModuleTreeList_SelectedNodeChanged(object sender, EventArgs e)
{
TreeNode sNode = tvModuleTreeList.SelectedNode;
int moduleId = isDynamicModule(sNode.Text);
if( moduleId >= 0 )
{
Add
sHelper.AddDynamicModule(sNode.Text, moduleId, "ContentPane", 1, "left" );
}
}
}