guna Samba
guna Samba

Reputation: 484

CSS In DNN Modules

How could i include the custom css & JavaScript for particular module in DotnetNuke?

I understand that it is not like normal ASP.Net page.

Upvotes: 6

Views: 6567

Answers (3)

Alejandro Haro
Alejandro Haro

Reputation: 1394

You can also use this:

<link rel="stylesheet" type="text/css" href="<%= ControlPath %>/module.css" />

Upvotes: 0

Hitesh Bavaliya
Hitesh Bavaliya

Reputation: 941

To add external JavaScript to a custom module:

string externaJs= "externaJs";
Type cstype = System.Reflection.MethodBase.GetCurrentMethod().GetType();
string cstext = "<script src=\"" +
                ResolveUrl("~/DesktopModules/ModuleName/js/JsName.js") +
                "\" type=\"text/javascript\"></script>";

if (!Page.ClientScript.IsClientScriptBlockRegistered(externaJs))
   Page.ClientScript.RegisterClientScriptBlock(cstype, externaJs, cstext, false);

Upvotes: -2

bdukes
bdukes

Reputation: 156075

If your module has a file named module.css in the root of the module folder, it will automatically get included on the page with the module.

For other CSS and for JavaScript, you should use the Client Resource Management framework to include the resources you want. Something like this:

<%@ Register TagPrefix="dnn" 
    Namespace="DotNetNuke.Web.Client.ClientResourceManagement" 
    Assembly="DotNetNuke.Web.Client" %>
 
<dnn:DnnCssInclude runat="server"
    FilePath="~/DesktopModules/MyModule/css/the-style.css" />
<dnn:DnnJsInclude runat="server"
    FilePath="~/DesktopModules/MyModule/js/the-script.js"
    ForceProvider="DnnFormBottomProvider" />

Upvotes: 17

Related Questions