Forum


HomeHomePremiumPremiumDevelopmentDevelopmentHow to include JQuery files in a DNN module?How to include JQuery files in a DNN module?
Previous
 
Next
New Post
2/17/2014 8:51 AM
 

Hello,

I am trying to move an asp.net application into a dnn module.

I've put my jquery code into a couple of files, which I've included in a user control (not View.ascx but my own user control which sits inside view.ascx).

I used the following lines which works fine in asp.net but isn't even seen in the page generated within the module:
<script src="../Scripts/ContentItemUserControl.js"></script>
<script src="../Scripts/PageBehindUserControl.js"></script>

I created these two lines by dragging the file onto the user control, to be sure there aren't any typos. My user control is inside a directory, hence the '../Scripts' prefix.

Checking under host settings I can see that JQuery 1.9.1 is included, so I haven't referenced the JQuery libraries from the control.

As suggested in the documentation, I also included the following line in the page load:
DotNetNuke.Framework.jQuery.RequestUIRegistration();

But the page isn't seeing my jquery files at all as they're not in the page.

Anyone got any suggestions? If anyone needs more information or anything isn't clear, please let me know.

Best Regards,

Steve

 
New Post
2/17/2014 11:36 AM
 

Steve,

You are correct that jQuery and jQueryUI are already registered on all pages in DNN, so there is no need to do this from your module.

It's not a good practice to hardcode script references in your control.

Then best way is to reference them using the ClientResourceManager.  I believe there is a high level overview in my tutorial: Client-centric Module Development.  For sure you can see in the sample project attached that I register my scripts and styles using ClientResourceManager in the Page_PreRender event of the View.ascx.

Using the ClientResourceManager ensures your scripts don't get registered more than once and SuperUsers can make choices as to how their website scripts are cached or composited (In Host > Host Settings > Advanced Settings > Client Resource Management).  

Scott

 
New Post
2/18/2014 8:48 AM
 

Hello Scott,

Thank you for your reply.

I looked at your video series, I couldn't see anything about the client resource manager there.

But I did use the code in your view.ascx to register the scripts in the prerender. There were a couple of other issues like setting clientmodeid to static and removing a virtual directory that visual studio seemed to create on the project.

Thank you for your help.

Best Regards,

Steve



 
New Post
2/19/2014 2:46 AM
 

Hi Scott,

Just one thought, using this method of attaching scripts:
ClientResourceManager.RegisterScript(this.Page, this.ControlPath + "Scripts/PageBehindUserControl.js");
ClientResourceManager.RegisterScript(this.Page, this.ControlPath + "Scripts/ContentItemUserControl.js");

They're still hard coded. Was there some way of not hard coding them?
To be honest, if they change, I'm probably going to be changing my asp.net/c# code too, so I'm not really bothered.

Best Regards,

Steve

 
New Post
2/19/2014 3:52 AM
 

Steve,

You can also register scripts from the ascx too.

<%@ Register TagPrefix="dnn" Namespace="DotNetNuke.Web.Client.ClientResourceManagement" Assembly="DotNetNuke.Web.Client" %>
<dnn:DnnJsInclude runat="server" FilePath="~/DesktopModules/MyModule/js/myjslib.js" />


 
Previous
 
Next
HomeHomePremiumPremiumDevelopmentDevelopmentHow to include JQuery files in a DNN module?How to include JQuery files in a DNN module?



Try FREE
30 days money back guaranteed