代码段与代码行注释_SkinSrc和ContainerSrc代码段

代码段与代码行注释

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:

有时在DotNetNuke模块开发中,您想在同一模块定义内交换控件。 在执行此操作时,DNN(有些令人讨厌)将外观和容器定义交换为默认的管理员选择。 要解决此问题,您需要在URL中指定SkinSrc和ContainerSrc。 这小段代码仅用于检查整个层次结构是否覆盖:

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

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).

这段代码将从标签页开始,然后移至外观路径的门户。 对于容器,它通过选项卡和门户在当前容器中向上移动。 如果找不到适当的Local或Global变体,则该代码将对其进行添加/删除(不同的位置以不同的方式存储这些字符串,这很烦人)。

The resulting string will be formatted like this:

结果字符串的格式如下:

&SkinSrc=[Relevant Skin Path]&ContainerSrc=[Relevant Container Path]

&SkinSrc = [相关皮肤路径]&ContainerSrc = [Releva nt容器路径]

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.

然后可以将此字符串添加到控件URL中,以在当前页面外观和容器中显示新控件。 这将使DNN无法显示当前的“仅管理员”页面外观或容器。 您的用户不会因为网站外观的变化而烦恼。

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.

遇到此问题时,唯一真正的选择是使用与您的设计和功能匹配的管理员皮肤。 这可能是非常有限的,因为通常管理员皮肤很容易保持启用附加菜单功能,以便在管理站点时易于导航。 这个问题在DNN 5.0之前的版本中非常普遍,在该版本中我广泛使用了此功能。 在DNN 5.0之后的版本中,控件交换变得更加用户友好。 但是,此方法仍然可以用于存储和检索单个控件的自定义外观。

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.

一个简单的函数可以处理一项相当平凡的任务,但是如果您要交换控件并遇到此问题,希望可以为您节省一些压力。

翻译自: https://www.experts-exchange.com/articles/3641/SkinSrc-and-ContainerSrc-Snippet.html

代码段与代码行注释

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值