Question

I'm trying to include JQuery in my DotNetNuke skin by adding these two lines of code at the top of my DNN skin:

<%                              
Page.ClientScript.RegisterClientScriptInclude("jquery", "http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js")
Page.ClientScript.RegisterStartupScript(Me.GetType(), "jQueryNoConflict", "jQuery.noConflict()", True) 
%>

Sadly, when I view source on my page, I don't see the appropriate tag referencing jquery.min.js anywhere. Is DotNetNuke somehow flushing out my requests to add script to my pages here? What am I missing? I'm somewhat of a DNN newbie.

Was it helpful?

Solution

Sigh. The solution is to make sure you put it in the Page_Load() method, and not the page rendering code itself. I suppose I was too late in the page lifecycle to do what I'd wanted to do.

<script runat="server">
    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Page.ClientScript.RegisterClientScriptInclude("jquery", "http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js")
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "jQueryNoConflict", "jQuery.noConflict();", True)
    End Sub
</script>

OTHER TIPS

What version of DNN are you using? DNN doesn't support including jQuery unless you're using DNN version 5. See here for more information

You can run into issues doing it this way, depending on which version your code will be targeting, and whether or not your module will be used multiple times on the one page.

I developed a set of methods to better handle this, which are version independent, so you can make a single line call like this:

InjectjQueryLibary(this.Page, false, false, false); 

The boolean values are 'include jQuery UI', 'use uncompressed version' and 'include noConflict()'.

The full code listing is available at this blog post: Including jQuery in a DotNetNuke Module with Version Independent Code

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top