Scott McCulloch's News Articles Module DNN 3.0 conversion question

Last post 01-16-2005 11:56 PM by Boskone. 2 replies.

Sort Posts:

  • Scott McCulloch's News Articles Module DNN 3.0 conversion question

    01-16-2005, 12:00 PM
    • Member
      665 point Member
    • jepper
    • Member since 03-18-2004, 9:29 PM
    • United States WV
    • Posts 133
    I am a big fan of Scott's modules and I have adapted his approach to module navigation in several of my own DNN 2 modules that work just fine. My problem is trying to convert my modules over to DNN 3. I am a newbie to .net coding and learning by example so please excuse any stupid questions.

    Below is the code I use in DNN 2 to load user controls within a module and this works fine in DNN 2.1.2

    DNN 2 Code

    Private Sub LoadControlType()
    Dim objPortalModuleControl As PortalModuleControl = CType(Me.LoadControl(m_controlToLoad), PortalModuleControl)
    objPortalModuleControl.ModuleConfiguration = Me.ModuleConfiguration
    plhControls.Controls.Add(objPortalModuleControl)
    End Sub

    DNN 3 Conversion Code

    Private Sub LoadControlType()
    Dim objPortalModuleControl As DotNetNuke.Entities.Modules.PortalModuleBase = CType(Me.LoadControl(m_controlToLoad), DotNetNuke.Entities.Modules.PortalModuleBase)
    objPortalModuleControl.ModuleConfiguration = Me.ModuleConfiguration
    plhControls.Controls.Add(objPortalModuleControl)
    End Sub

    The above conversion code gives the following error:

    Unhandled error loading module.
    DotNetNuke.Services.Exceptions.ModuleLoadException: Unhandled Error Adding Module to TopPane ---> System.InvalidCastException: Specified cast is not valid. at BusinessWebPortals.Modules.Cinema.MovieTime.LoadControlType() in C:\Inetpub\DNN3\DesktopModules\Cinema\MovieTime.ascx.vb:line 214 at BusinessWebPortals.Modules.Cinema.MovieTime.Page_Init(Object sender, EventArgs e) in C:\Inetpub\DNN3\DesktopModules\Cinema\MovieTime.ascx.vb:line 73 at System.Web.UI.Control.OnInit(EventArgs e) at System.Web.UI.UserControl.OnInit(EventArgs e) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.InitRecursive(Control namingContainer) at System.Web.UI.Control.AddedControl(Control control, Int32 index) at System.Web.UI.ControlCollection.Add(Control child) at DotNetNuke.UI.Skins.Skin.InjectModule(Control objPane, ModuleInfo objModule, PortalSettings PortalSettings) in C:\Inetpub\DNN3\admin\Skins\Skin.vb:line 727 --- End of inner exception stack trace ---

    If anyone could shed some light on this problem I would appreciate the help. I don't know if I am using the correct class on the conversion or not.

    Scott if you happen to read this post I would like to thank you for creating the excellent modules you have. I have learned a great deal from your experience. I am a long long long way from understanding only a fraction of what you do in you modules. Thank again. If you could help in any way it would be nice.

  • Re: Scott McCulloch's News Articles Module DNN 3.0 conversion question

    01-16-2005, 1:12 PM
    • Participant
      1,235 point Participant
    • ikamiksok
    • Member since 11-12-2003, 12:08 PM
    • Posts 247
    The code looks correct to me.

    I'm not sure about this specific error, but if you have code which loads a control (in this case whatever m_controlToLoad points to) dynamically and that code has problems, then you will get a generic fail to load error on the page. I had trouble with this myself but not sure if this your problem or not.

    Perhaps you can provide more information as the MovieTime code does not appear to be a part of the News Articles module as this is what appears to be failing?

    I know with the DNN2 to DNN3 conversion you may see some invalid cast errors. This is because some types have changed such as retrieving usernames or userids. So look for this at line 214 or 73 of MovieTime.ascx.vb.

    Jason
  • Re: Scott McCulloch's News Articles Module DNN 3.0 conversion question

    01-16-2005, 1:56 PM
    • Member
      465 point Member
    • Boskone
    • Member since 01-01-2003, 8:11 AM
    • Canada
    • Posts 93
    Try this:

    [code]
    Dim objPortalModuleBase As Entities.Modules.PortalModuleBase = CType(Me.LoadControl(m_controlToLoad), Entities.Modules.PortalModuleBase)
    'Set Language file ID
    objPortalModuleBase.ID = System.IO.Path.GetFileNameWithoutExtension(m_controlToLoad)
    objPortalModuleBase.ModuleConfiguration = Me.ModuleConfiguration

    ' Load the appropriate control
    plhControl.Controls.Clear()

    plhControl.Controls.Add(objPortalModuleBase)
    [/code]
  • Re: Scott McCulloch's News Articles Module DNN 3.0 conversion question

    01-16-2005, 10:30 PM
    • Member
      665 point Member
    • jepper
    • Member since 03-18-2004, 9:29 PM
    • United States WV
    • Posts 133
    Boskone thanks your insight did the trick I also went to your site and downloaded the PageView DNN3 module and source.

    I still received the same error but after looking at your code I figured out that the control page I was trying to load needed to inherit from the PortalModuleBase.

    DNN2 module Inherits from the System.Web.UI.UserControl Class

    DNN3 module Inherits from the Entities.modules.PortalModuleBase Class

    I see you also like the way Scott handled module navigation. One question about the module settings? Did you try loading the settings page as a control on the main page and not within the edit dropdown? I know this is the way DNN3 is suppose to handle settings but I think this is combursome and took me a some time to figure out where it was. I think if it will work I am going to stick with the way Scott did admin options in the News Articles Module. If you have admin or edit rights you will see the link to the settings page directly on the main page.

    BTW your site looks good and I will keep an eye on it to change over to DNN3.

    Thanks Again
    James
  • Re: Scott McCulloch's News Articles Module DNN 3.0 conversion question

    01-16-2005, 11:14 PM
    • Member
      465 point Member
    • Boskone
    • Member since 01-01-2003, 8:11 AM
    • Canada
    • Posts 93
    Thanks jepper. Yes I did follow Scott's examples. They are very good guides.

    I never tried to put the settings on their own page, I just followed the DNN3 module structures and put the settings with all the other module settings.
    I think it makes more sense to follow convention and place the settings the same as the rest of the modules.

Page 1 of 1 (5 items)