【问题标题】:How to add a Lightbox to a custom DotNetNuke module如何将灯箱添加到自定义 DotNetNuke 模块
【发布时间】:2010-07-26 22:05:35
【问题描述】:

我正在开发一个需要使用 Lightbox 的自定义 DotNetNuke 模块。将 Lightbox 所需的 javascript 添加到 DNN 模块的最佳方法是什么?

我见过的几乎所有解决方案都涉及将 javascript 引用添加到皮肤文件。还有另一种方法可以做到这一点吗?即使对于不需要它们的模块,我也不希望加载这些 javascript 文件。

================================================ =======================

感谢 spinon 的帮助,这是我正在使用的解决方案:

Dim csMgr As ClientScriptManager = Page.ClientScript
Dim Name As String = "prototype.js"
Dim ScriptPath As String = "http://dnn/js/prototype.js"
Dim Type As Type = Me.GetType

'check if script is already registered
If Not csMgr.IsClientScriptBlockRegistered(Type, Name) Then
    Dim scriptText As New StringBuilder

    scriptText.AppendLine()
    scriptText.Append("<script src=""")
    scriptText.Append(ScriptPath)
    scriptText.Append(""" type=""text/javascript""></script>")
    scriptText.AppendLine()

    'register script
    csMgr.RegisterClientScriptBlock(Me.GetType, Name, scriptText.ToString())
End If

【问题讨论】:

  • 还有另一种方法,将你的js放在模块根目录中并使用:

标签: .net javascript lightbox dotnetnuke


【解决方案1】:

如果仅适用于某些模块,您始终可以将它们直接包含到您的模块中。生成的 HTML 不会很漂亮,但这是一种解决方案。

或从 .net 代码访问 .net 脚本管理器。我现在忘记了类名,但你可以让它加载脚本。

无论哪种方式,这两种解决方案都会避免为所有页面加载 js,如果将其放入皮肤中会发生这种情况。

编辑:这是课程信息:

Page.ClientScript.RegisterClientScriptBlock(....); 

http://msdn2.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerclientscriptblock.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-02
    • 1970-01-01
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多