Community Pick: Many members of our community have endorsed this article.

SkinSrc and ContainerSrc Snippet

Published:
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)
                                  Else
                                      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)
                                  Else
                                      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.
0
3,982 Views

Comments (0)

Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.