[Webinar] Streamline your web hosting managementRegister Today


SkinSrc and ContainerSrc Snippet

Published on
9,349 Points
Last Modified:
Community Pick
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need to specify the SkinSrc and ContainerSrc in the URL.  This little chunk of code provides just that checking the full hierarchy for overrides:

Protected Function GetSkinContainerSrc() As String

    Dim strReturn As String = String.Empty
    Dim objTabs As New TabController()
    Dim objTab As DotNetNuke.Entities.Tabs.TabInfo = objTabs.GetTab(Me.TabId)

    'Get the skin source
    'Check the tab settings first.
    Dim strSkin As String = objTab.SkinSrc

    If strSkin = String.Empty Then
        'Not in the tab settings, check the portal
        strSkin = PortalSettings.PortalSkin.SkinSrc
    End If

    'Cleanup the string if it doesn't have the global/local information.
    If strSkin <> String.Empty Then
        If strSkin.IndexOf("/Portals/") >= 0 Then
            If strSkin.IndexOf("/Portals/_default/") >= 0 Then
                strSkin = "[G]" & strSkin.Substring(strSkin.IndexOf("/Skins/") + 1)
                strSkin = "[L]" & strSkin.Substring(strSkin.IndexOf("/Skins/") + 1)
            End If
        End If

        strReturn += "&SkinSrc=" & Server.UrlEncode(strSkin.Replace(".ascx", String.Empty))
    End If

    'Get the container source
    'Check the module settings for the container first.
    Dim strContainer As String = Me.ModuleConfiguration.ContainerSrc

    If strContainer = String.Empty Then
        'Not in the module, check the tab.
        strContainer = objTab.ContainerSrc

        If strContainer = String.Empty Then
            'Not in the tab, check the portal
            strContainer = PortalSettings.PortalContainer.SkinSrc
        End If
    End If

    'Cleanup the string if it doesn't have the global/local information.
    If strContainer <> String.Empty Then
        If strContainer.IndexOf("/Portals/") >= 0 Then
            If strContainer.IndexOf("/Portals/_default/") >= 0 Then
                strContainer = "[G]" & strContainer.Substring(strContainer.IndexOf("/Containers/") + 1)
                strContainer = "[L]" & strContainer.Substring(strContainer.IndexOf("/Containers/") + 1)
            End If
        End If

        strReturn += "&ContainerSrc=" & Server.UrlEncode(strContainer.Replace(".ascx", String.Empty))
    End If

    Return strReturn

End Function

Open in new window

This code will start at the Tab and then move to the Portal for the Skin path.  For the container it moves through the current container up through the Tab and Portal.  The code handles adding/removing the appropriate Local or Global variations to the string if they aren't found (different locations store these strings differently, very annoying).

The resulting string will be formatted like this:
&SkinSrc=[Relevant Skin Path]&ContainerSrc=[Relevant Container Path]

This string can then be added to your control URL to display the new control within the current page skin and container.  This will keep DNN from displaying the current Admin only page skin or container.  Your users won't be as jarred by a change in visual look and feel to the site.

The only real alternative when faced with this issue is to use an admin skin that matches your design and functionality.  This can be very limiting since admin skins in general are nice to keep addition menu features enabled for ease of navigation while administering the site.  This issue was very prevalent in pre DNN 5.0 versions where I have used this function extensively.  In post DNN 5.0 control swapping has become much more user friendly; however this method can still come into use for storing and retrieving custom skins for individual controls.

One simple function to handle a rather mundane task, but if you are swapping a control and come across this issue hopefully this will save you a few stressful hours.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Join & Write a Comment

How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month