<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>michael pardo &#187; jQuery</title>
	<atom:link href="http://michaelpardo.com/category/development/javascript/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://michaelpardo.com</link>
	<description>software developer</description>
	<lastBuildDate>Fri, 14 May 2010 13:21:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=2844</generator>
		<item>
		<title>Including jQuery in DotNetNuke</title>
		<link>http://michaelpardo.com/2009/06/including-jquery-in-dotnetnuke/</link>
		<comments>http://michaelpardo.com/2009/06/including-jquery-in-dotnetnuke/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 14:00:12 +0000</pubDate>
		<dc:creator>Michael Pardo</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[DotNetNuke]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.michaelpardo.com/?p=61</guid>
		<description><![CDATA[As of DNN 5, jQuery is now included. This is great, unless you&#8217;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 [...]]]></description>
			<content:encoded><![CDATA[<p>As of DNN 5, jQuery is now included. This is great, unless you&#8217;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.</p>
<p>Notice the code is placed in the <strong>Page_PreRender</strong> event. This is an absolute must.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_PreRender<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Items</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;jquery_registered&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">// load jQuery</span>
		RegisterJavascript<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;/DesktopModules/MyModule/js/jquery.js&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #008080; font-style: italic;">// let other modules know about jQuery</span>
		HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Items</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;jquery_registered&quot;</span>, <span style="color: #666666;">&quot;true&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">// load all the plugins</span>
	RegisterJavascript<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;/DesktopModules/MyModule/js/jquery.foo.js&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	RegisterJavascript<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;/DesktopModules/MyModule/js/jquery.bar.js&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Here&#8217;s the RegisterJavascript method I use.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> RegisterJavascript<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> fullPath<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	var script <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;script&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	script.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;type&quot;</span>, <span style="color: #666666;">&quot;text/javascript&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	script.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;src&quot;</span>, fullPath<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	Page.<span style="color: #0000FF;">Header</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>script<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Now you can continue using jQuery without any worries of conflict.</p>
<p>One mistake that had me tripped up for a while was an include of jQuery in the skin. I didn&#8217;t realize it was there and I couldn&#8217;t figure out why none of my plugins worked. As a general rule I never include jQuery in the skin.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelpardo.com/2009/06/including-jquery-in-dotnetnuke/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
