Including jQuery in DotNetNuke

17 Jun

As of DNN 5, jQuery is now included. This is great, unless you’re distributing a module and you want it to work with versions below 5 also. Fortunately there is a way to check if jQuery has already been included, thereby avoiding conflicts.

Notice the code is placed in the Page_PreRender event. This is an absolute must.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
protected void Page_PreRender(object sender, EventArgs e)
{
	if (HttpContext.Current.Items["jquery_registered"] == null)
	{
		// load jQuery
		RegisterJavascript("/DesktopModules/MyModule/js/jquery.js");
		// let other modules know about jQuery
		HttpContext.Current.Items.Add("jquery_registered", "true");
	}
 
	// load all the plugins
	RegisterJavascript("/DesktopModules/MyModule/js/jquery.foo.js");
	RegisterJavascript("/DesktopModules/MyModule/js/jquery.bar.js");
}

Here’s the RegisterJavascript method I use.

1
2
3
4
5
6
7
8
protected void RegisterJavascript(string fullPath)
{
	var script = new HtmlGenericControl("script");
	script.Attributes.Add("type", "text/javascript");
	script.Attributes.Add("src", fullPath);
 
	Page.Header.Controls.Add(script);
}

Now you can continue using jQuery without any worries of conflict.

One mistake that had me tripped up for a while was an include of jQuery in the skin. I didn’t realize it was there and I couldn’t figure out why none of my plugins worked. As a general rule I never include jQuery in the skin.

Visual Studio and SubSonic

17 Jun

If you aren’t using SubSonic yet, you should be. You can find out more at subsonicproject.com. Here’s the easiest way to get SubSonic working smoothly from within Visual Studio.

Download the SubSonic source from http://subsonicproject.googlecode.com/files/SubSonic_2.1_Final_Source.zip and extract it. I chose to create a folder for SubSonic in “C:\Program Files\”.

SubSonic Folder

SubSonic Folder

Next, in Visual Studio click the “External Tools…” menu item from the “Tools” menu. A dialog box will pop up allowing you to manage the external tools. Click “Add” and enter the following:

External Tools Dialog

External Tools Dialog

Title: SubSonic (or whatever you want really)
Command: C:\YOUR_SUBSONIC_PATH\SubSonic2.2\SubCommander\sonic.exe
Arguments: generate /out $(ProjectDir)/Generated
Initial directory: $(ProjectDir)

I check “User Output window”. If you don’t a console window will popup every time you run the command.

Now you will have a “SubSonic” menu item in your “Tools” menu which will generate all your subsonic classes.

Tools Menu

Tools Menu

Of course, you need to have your app.config/web.config setup with SubSonic for the classes to generate. You can find more information about doing that here: http://subsonicproject.com/setup/gettingstarted/.

DotNetNuke web services

16 Jun

I recently had to write a web service to interact with the DNN database. Some of the things I wanted to do worked best with the DotNetNuke binary. When I finally got to testing out the methods that used the DNN library, it blew up. After much deliberation, I figured out the minimum requirements for using DotNetNuke.dll in your project. This zip file contains everything you’ll need…

Minimal DNN Project (114)

Blogging motivation

13 May

This is the fourth blog post of mine. Lame right? I’m going to attempt to post more with a different way of looking at blogging. I dont really care to share my thoughts with the whole world, but I would like to keep track of all the techniques I learn. My blog would be a great place to do that right?

We’ll see how well this actually works.

Marston-Pardo Union

28 Oct

I’m getting married this Saturday, November 1st, 2008. Then a week in Mexico!

Check out the wedding website: http://amanda.michaelpardo.com