<?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>Encosia &#187; jQuery</title>
	<atom:link href="http://encosia.com/category/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://encosia.com</link>
	<description>ASP.NET and AJAX code, ideas, and examples.</description>
	<lastBuildDate>Tue, 09 Mar 2010 08:34:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How you can force the Ajax Script Loader to use jQuery 1.4</title>
		<link>http://encosia.com/2010/01/15/how-you-can-force-the-ajax-script-loader-to-use-jquery-1-4/</link>
		<comments>http://encosia.com/2010/01/15/how-you-can-force-the-ajax-script-loader-to-use-jquery-1-4/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 05:24:57 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/?p=962</guid>
		<description><![CDATA[If you’ve already begun using Microsoft’s new Ajax Script Loader with a CDN-hosted version of jQuery, today’s release of jQuery 1.4 may have left you wondering how to upgrade. Personally, I didn’t want to wait on a new version of Start.js, nor did I want to abandon the script loader now that I’ve become accustomed [...]<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2010/01/15/how-you-can-force-the-ajax-script-loader-to-use-jquery-1-4/">How you can force the Ajax Script Loader to use jQuery 1.4</a></p>
]]></description>
			<content:encoded><![CDATA[<p>If you’ve already begun using Microsoft’s new <a href="http://www.asp.net/ajaxLibrary/Ajax%20Script%20Loader.ashx" target="_blank">Ajax Script Loader</a> with a CDN-hosted version of jQuery, today’s release of jQuery 1.4 may have left you wondering how to upgrade. Personally, I didn’t want to wait on a new version of Start.js, nor did I want to abandon the script loader now that I’ve become accustomed to its benefits.</p>
<p>No doubt, an upcoming ASP.NET Ajax Library iteration will update Start.js’ jQuery definition to reference jQuery 1.4.x. Regardless, <strong>knowing how to patch the script loader on your own terms is something that will be of recurring usefulness</strong>.</p>
<p>Luckily, <a href="http://weblogs.asp.net/bleroy/archive/2009/11/23/enabling-the-asp-net-ajax-script-loader-for-your-own-scripts.aspx" target="_blank">the script loader is open and extensible</a> enough that it’s possible to change which script versions are used. So, I want to briefly show you <strong>how the script loader defines JavaScript includes</strong> and how you can <strong>patch those definitions without modifying Start.js</strong> itself.</p>
<h3>Using the script loader to inject jQuery</h3>
<p>If you aren’t familiar with the script loader itself or with using it to asynchronously request jQuery, I recommend checking out <a href="http://www.asp.net/ajaxlibrary/Ajax%20Script%20Loader.ashx" target="_blank">its documentation and examples on the new ASP.NET Ajax Wiki</a>.</p>
<p>To use it most basically, simply include a reference to Start.js either locally or on the Microsoft CDN, and then use this JavaScript to instruct the script loader to inject jQuery into the page:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Instruct the script loader to request</span>
<span style="color: #006600; font-style: italic;">//  jQuery in the background.</span>
Sys.<span style="color: #660066;">require</span><span style="color: #009900;">&#40;</span>Sys.<span style="color: #660066;">scripts</span>.<span style="color: #660066;">jQuery</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// This callback runs later, after jQuery</span>
<span style="color: #006600; font-style: italic;">//  has been asynchronously loaded.</span>
Sys.<span style="color: #660066;">onReady</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Loaded jQuery &quot;</span> <span style="color: #339933;">+</span> jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">jquery</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Monitoring the request in Firebug illuminates what that Sys.require statement triggered in the background:</p>
<p><img style="border: #333 1px solid;" alt="Observing the script loader&#39;s default jQuery injection behavior" src="http://encosia.com/blog/wp-content/uploads/2010/01/script-loader-default.png" width="490" height="142" /></p>
<p>As you can see, the end result is pretty straightforward. The primary benefit of this asynchronous loading technique is that <strong>scripts loaded through the script loader are non-blocking and may be loaded in parallel</strong>. By contrast, JavaScript includes referenced through HTML script elements block all rendering and further requests until they are parsed and executed. <a href="http://www.stevesouders.com/blog/2009/04/27/loading-scripts-without-blocking/" target="_blank">The difference is often significant</a>.</p>
<p>Now, if only it were injecting jQuery 1.4 instead of 1.3.2.</p>
<h3>Understanding how Sys.scripts.jQuery is defined</h3>
<p>The Sys.scripts.jQuery parameter to the script loader is actually just a JavaScript object that defines a few parameters about the include. Here is how that is defined in Start.js (edited slightly for readability here):</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> path <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">location</span>.<span style="color: #660066;">protocol</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;https&quot;</span> <span style="color: #339933;">?</span> <span style="color: #3366CC;">&quot;https&quot;</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;http&quot;</span><span style="color: #009900;">&#41;</span> 
           <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;://ajax.microsoft.com/ajax/&quot;</span><span style="color: #339933;">;</span>
&nbsp;
loader.<span style="color: #660066;">defineScripts</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span>
 <span style="color: #009900;">&#123;</span> <span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;jQuery&quot;</span><span style="color: #339933;">,</span>
   releaseUrl<span style="color: #339933;">:</span> path <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;jquery/jquery-1.3.2.min.js&quot;</span><span style="color: #339933;">,</span>
   debugUrl<span style="color: #339933;">:</span> path <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;jquery/jquery-1.3.2.js&quot;</span><span style="color: #339933;">,</span>
   isLoaded<span style="color: #339933;">:</span> <span style="color: #339933;">!!</span>window.<span style="color: #660066;">jQuery</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you’re using a local copy of Start.js, one option is to modify this jQuery script definition inside Start.js itself. However, I discourage that alternative. Not only would it require constant, manual maintenance after every new release, but it isn’t an option when using <a href="http://www.asp.net/ajaxLibrary/cdn.ashx" target="_blank">the Microsoft Ajax CDN’s</a> copy of Start.js.</p>
<h3>Defining a new target for it</h3>
<p>Another option is to <strong>simply modify the Sys.scripts.jQuery object itself</strong>. Letting Start.js initialize the definition with jQuery 1.3.2’s path doesn’t hurt anything as long as we redefine it before calling Sys.require.</p>
<p>Inspecting the Sys.scripts collection in Firebug reveals how straightforward that modification will be:</p>
<p><img style="border: #333 1px solid;" alt="Inspecting Sys.scripts.jQuery in Firebug" src="http://encosia.com/blog/wp-content/uploads/2010/01/Sys.scripts.jQuery-inspection.png" width="490" height="124" /></p>
<p>Thanks to to <a href="http://encosia.com/2009/09/21/updated-see-how-i-used-firebug-to-learn-jquery/" target="_blank">the power of interactively interrogating the object in Firebug</a>, it becomes clear that updating the releaseUrl and debugUrl properties of that object should be all that is necessary.</p>
<h3>Updating the example to use jQuery 1.4</h3>
<p>Because jQuery 1.4 isn’t available on the Microsoft CDN yet, I’m going to target <a href="http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/">Google’s AJAX Libraries CDN for jQuery</a> instead. Once Microsoft’s CDN is updated with jQuery 1.4.x, this approach will work for either CDN.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// These re-definitions must be executed after </span>
<span style="color: #006600; font-style: italic;">//  Start.js, but before Sys.require.</span>
<span style="color: #003366; font-weight: bold;">var</span> CDN <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://ajax.googleapis.com/ajax/libs&quot;</span><span style="color: #339933;">;</span>
&nbsp;
Sys.<span style="color: #660066;">scripts</span>.<span style="color: #660066;">jQuery</span>.<span style="color: #660066;">releaseUrl</span> <span style="color: #339933;">=</span> CDN <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/jquery/1.4.1/jquery.min.js&quot;</span><span style="color: #339933;">;</span>
Sys.<span style="color: #660066;">scripts</span>.<span style="color: #660066;">jQuery</span>.<span style="color: #660066;">debugUrl</span>   <span style="color: #339933;">=</span> CDN <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/jquery/1.4.1/jquery.js&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Instruct the script loader to request</span>
<span style="color: #006600; font-style: italic;">//  jQuery in the background.</span>
Sys.<span style="color: #660066;">require</span><span style="color: #009900;">&#40;</span>Sys.<span style="color: #660066;">scripts</span>.<span style="color: #660066;">jQuery</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// This callback runs later, after jQuery</span>
<span style="color: #006600; font-style: italic;">//  has been asynchronously loaded.</span>
Sys.<span style="color: #660066;">onReady</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  console.<span style="color: #660066;">log</span><span style="color: #3366CC;">&quot;Loaded jQuery &quot;</span> <span style="color: #339933;">+</span> jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">jquery</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That’s all there is to it. Reviewing the requests in Firebug again, you can see that the same Sys.require statement is indeed now loading jQuery 1.4 from Google’s CDN:</p>
<p><img style="border: #333 1px solid;" alt="Observing the script loader&#39;s behavior after modifying Sys.scripts.jQuery" src="http://encosia.com/blog/wp-content/uploads/2010/01/script-loader-modified.png" width="490" /></p>
<h3>Bonus: jQuery Validate 1.6</h3>
<p>As I write this, Start.js’ definition for Sys.scripts.jQueryValidate is still targeting version 1.5.5 of the plugin, but <a href="http://www.asp.net/ajaxLibrary/CDNjQueryValidate16.ashx" target="_blank">1.6 is the current version</a>.</p>
<p>Using what&#8217;s been covered in this post, pointing the script loader at the newest version of jQuery Validate is no problem:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> MSCDN <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://ajax.microsoft.com/ajax&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> GoogCDN <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;http://ajax.googleapis.com/ajax/libs&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Please forgive my ugly formatting to make this fit. Do not try </span>
<span style="color: #006600; font-style: italic;">//  this at home (unless your editor is only 492px too).</span>
Sys.<span style="color: #660066;">scripts</span>.<span style="color: #660066;">jQuery</span>.<span style="color: #660066;">releaseUrl</span> <span style="color: #339933;">=</span> 
  GoogCDN <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/jquery/1.4.1/jquery.min.js&quot;</span><span style="color: #339933;">;</span>
Sys.<span style="color: #660066;">scripts</span>.<span style="color: #660066;">jQuery</span>.<span style="color: #660066;">debugUrl</span> <span style="color: #339933;">=</span> 
  GoogCDN <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/jquery/1.4.1/jquery.js&quot;</span><span style="color: #339933;">;</span>
&nbsp;
Sys.<span style="color: #660066;">scripts</span>.<span style="color: #660066;">jQueryValidate</span>.<span style="color: #660066;">releaseUrl</span> <span style="color: #339933;">=</span> 
  MSCDN <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/jQuery.Validate/1.6/jQuery.Validate.min.js&quot;</span><span style="color: #339933;">;</span>
Sys.<span style="color: #660066;">scripts</span>.<span style="color: #660066;">jQueryValidate</span>.<span style="color: #660066;">debugUrl</span> <span style="color: #339933;">=</span> 
  MSCDN <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;/jQuery.Validate/1.6/jQuery.Validate.js&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Instruct the script loader to request</span>
<span style="color: #006600; font-style: italic;">//  jQuery and jQuery Validate in the background.</span>
Sys.<span style="color: #660066;">require</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#91;</span>Sys.<span style="color: #660066;">scripts</span>.<span style="color: #660066;">jQuery</span><span style="color: #339933;">,</span> Sys.<span style="color: #660066;">scripts</span>.<span style="color: #660066;">jQueryValidate</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// This callback runs later, after both jQuery</span>
<span style="color: #006600; font-style: italic;">//  and jQuery Validate have been loaded.</span>
Sys.<span style="color: #660066;">onReady</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Loaded jQuery &quot;</span> <span style="color: #339933;">+</span> jQuery.<span style="color: #660066;">fn</span>.<span style="color: #660066;">jquery</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The jQuery Validate situation is a good example of why knowing how to update these script definitions yourself is worthwhile. Because the script loader was designed to be so flexible, there’s no need to wait on a new release of Start.js or give up its benefits.</p>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2010/01/15/how-you-can-force-the-ajax-script-loader-to-use-jquery-1-4/">How you can force the Ajax Script Loader to use jQuery 1.4</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2010/01/15/how-you-can-force-the-ajax-script-loader-to-use-jquery-1-4/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Mastering jQuery now available at TekPub</title>
		<link>http://encosia.com/2009/12/16/mastering-jquery-now-available-at-tekpub/</link>
		<comments>http://encosia.com/2009/12/16/mastering-jquery-now-available-at-tekpub/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 14:52:42 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/?p=951</guid>
		<description><![CDATA[
If you haven’t been following the progress of Rob Conery and James Avery’s new venture, TekPub, you’ve been missing out on some great instructional videos. I especially like that they trend slightly Alt.NET, giving you more balanced information than is sometimes available from “official” .NET screencasts.
For the past few weeks, I’ve been working with James [...]<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/12/16/mastering-jquery-now-available-at-tekpub/">Mastering jQuery now available at TekPub</a></p>
]]></description>
			<content:encoded><![CDATA[<p><a href="http://tekpub.com/view/jquery/1" target="_blank"><img border="0" alt="Mastering jQuery" src="http://encosia.com/blog/wp-content/uploads/2009/12/tekpub-mastering-jquery.jpg" width="492" height="242" /></a></p>
<p>If you haven’t been following the progress of Rob Conery and James Avery’s new venture, <a href="http://tekpub.com" target="_blank">TekPub</a>, you’ve been missing out on some great instructional videos. I especially like that they trend slightly Alt.NET, giving you more balanced information than is sometimes available from “official” .NET screencasts.</p>
<p>For the past few weeks, I’ve been working with James to record a series of episodes for TekPub myself: <strong>Mastering jQuery</strong>.</p>
<blockquote><p>Mastering jQuery walks through the basics of using jQuery, the revolutionary JavaScript framework that makes writing client-side code fun and easy, and then dives into the details of writing AJAX enabled ASP.NET MVC and ASP.NET Web Forms applications. We will also cover popular plugins and extending jQuery in future episodes.</p></blockquote>
<p>Today, the first video in that series is available: <a href="http://tekpub.com/view/jquery/1" target="_blank">Getting Started with jQuery</a>.</p>
<blockquote><p>In this episode we cover the basics of getting started with jQuery. We start with a basic HTML page and show how to include jQuery, how to write your first code, and explain all of the moving pieces and how they work.</p></blockquote>
<p>If you’ve been following my site and working with jQuery already, the first episode may sound elementary, but there’s going to be something for everyone before the series is finished. By the third episode, we’re already into topics like making <strong>AJAX calls to MVC controller actions</strong> and <strong>progressively enhancing an entry form</strong> with the jQuery form plugin.</p>
<p>I hope you&#8217;ll head over to TekPub, and <a href="http://tekpub.com/view/jquery/1" target="_blank">have a look for yourself</a>.</p>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/12/16/mastering-jquery-now-available-at-tekpub/">Mastering jQuery now available at TekPub</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2009/12/16/mastering-jquery-now-available-at-tekpub/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Emulate ASP.NET validation groups with jQuery validation</title>
		<link>http://encosia.com/2009/11/24/asp-net-webforms-validation-groups-with-jquery-validation/</link>
		<comments>http://encosia.com/2009/11/24/asp-net-webforms-validation-groups-with-jquery-validation/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 17:51:37 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/?p=948</guid>
		<description><![CDATA[In my most recent post, I demonstrated a workaround to allow using the jQuery validation plugin with WebForms pages. The basic idea was to trigger validation only on submissions that occurred within a single logical form, instead of catching submissions anywhere on WebForms’ all-encompassing physical form.
This approach worked fine for a single logical form, but [...]<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/11/24/asp-net-webforms-validation-groups-with-jquery-validation/">Emulate ASP.NET validation groups with jQuery validation</a></p>
]]></description>
			<content:encoded><![CDATA[<p>In my most recent post, I demonstrated a workaround to allow <a href="http://encosia.com/2009/11/04/using-jquery-validation-with-asp-net-webforms/" target="_blank">using the jQuery validation plugin with WebForms pages</a>. The basic idea was to trigger validation only on submissions that occurred within a single logical form, instead of catching submissions anywhere on WebForms’ all-encompassing physical form.</p>
<p>This approach worked fine for a single logical form, but wasn&#8217;t robust enough when handling validation for multiple logical forms on a single page. Additionally, it did not properly handle the enter key, allowing users to (perhaps accidentally) slip past validation if they simply hit the enter key within a TextBox.</p>
<p>In this post, we will continue by refining the solution from last time. So, if you haven’t read the previous post, familiarize yourself with it first. Specifically, this post will cover how to <strong>implement an analogue of WebForms’ ValidationGroup</strong>, use that to <strong>independently validate multiple form regions</strong>, <strong>handle the enter key</strong>, and <strong>refactor the final solution</strong> to minimize duplicated code.</p>
<h3>ValidationGroups</h3>
<p>In WebForms, we have the concept of a <strong><a href="http://msdn.microsoft.com/en-us/library/ms227424.aspx" rel="nofollow" target="_blank">ValidationGroup</a></strong> to mitigate the issues that come with wrapping the entire page in a single form element. Whether right or wrong in principle, this scheme does a pretty good job of keeping the ASP.NET Validation controls from getting their wires crossed on complex forms.</p>
<p>However, using ASP.NET’s ValidationGroups requires that you use the WebForms validation controls, which generates quite a bit of cruft in your markup and injects two additional script references on your page.</p>
<p><img style="border: 1px solid #000;" alt="An example of some of the client-side code the ASP.NET Validators generates" src="http://encosia.com/blog/wp-content/uploads/2009/11/WebForms-validator-output.png" width="490" height="111" /></p>
<p>If you’re like me, trying to trend away from client-heavy WebForms pages <strong>these side-effects are prohibitive</strong>.</p>
<h3>Emulating Validation Groups</h3>
<p>Though its implementation renders a bit messy on the client-side, the WebForms paradigm of a ValidationGroup is exactly what we need for segregating our physical form element into logical forms. In fact, I’m going to use the same nomenclature in this example (ValidationGroup and CausesValidation).</p>
<p>Using CSS classes as flags is a great way to emulate that concept in plain (X)HTML markup. Especially when using jQuery, CSS “flags” are a great way to tag elements with arbitrary attributes, that are easy to find with simple DOM selectors later. Taking the form shown in my previous post and tagging its fieldsets with a validationGroup class, we end up with this markup:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fieldset</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;validationGroup&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;legend&gt;</span></span>Returning customer?  Login here<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/legend&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #060; font-style: italic;">&lt;!-- Username and Password labels and inputs here --&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fieldset&gt;</span></span></pre></div></div>

<p>Not a very large change, but it allows us to keep these logical forms separate, both when performing validation and when initially setting up their validation triggers.</p>
<h3>Creating a CausesValidation counterpart</h3>
<p>ValidationGroups may control the organization of logical forms, but it’s the controls marked with the CausesValidation property that drive validation of those forms. In similar fashion, we need a way to indicate which elements should trigger our own emulation of WebForms’ grouped validation.</p>
<p>Sticking with the same naming scheme and CSS flagging technique, it makes sense to tag our Button controls with a .causesValidation class:</p>

<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;">&lt;fieldset class=&quot;validationGroup&quot;&gt;
  &lt;legend&gt;Returning customer?  Login here&lt;/legend&gt;
&nbsp;
  <span style="color: #060; font-style: italic;">&lt;!-- Username and Password labels and inputs here --&gt;</span>
&nbsp;
  &lt;asp:Button runat=&quot;server&quot; ID=&quot;Login&quot; Text=&quot;Login&quot; 
              CssClass=&quot;causesValidation&quot; /&gt;
&lt;/fieldset&gt;</pre></div></div>

<p>Now we just need to wire up functionality to make those causesValidation flags actually do something.</p>
<h3>Acting on the validationGroup flag</h3>
<p>With the markup modified to allow selective targeting of the validation groups, the next step is implementing validation functionality that leverages that targeting. Using jQuery’s powerful CSS-based selectors, that isn’t difficult:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#form1&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">validate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> onsubmit<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Search for controls marked with the causesValidation flag </span>
  <span style="color: #006600; font-style: italic;">//  that are contained anywhere within elements marked as </span>
  <span style="color: #006600; font-style: italic;">//  validationGroups, and wire their click event up.</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.validationGroup .causesValidation'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Ascend from the button that triggered this click event </span>
    <span style="color: #006600; font-style: italic;">//  until we find a container element flagged with </span>
    <span style="color: #006600; font-style: italic;">//  .validationGroup and store a reference to that element.</span>
    <span style="color: #003366; font-weight: bold;">var</span> $group <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.validationGroup'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> isValid <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// Descending from that .validationGroup element, find any input</span>
    <span style="color: #006600; font-style: italic;">//  elements within it, iterate over them, and run validation on </span>
    <span style="color: #006600; font-style: italic;">//  each of them.</span>
    $group.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">':input'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">valid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        isValid <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isValid<span style="color: #009900;">&#41;</span>
      evt.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><em>Note: For more explanation of any uncommented code above, be sure to see <a href="http://encosia.com/2009/11/04/using-jquery-validation-with-asp-net-webforms/" target="_blank">the previous post in this series</a>. Those parts are explained in detail there.</em></p>
<p>This sets up a click event handler on any element flagged with the causesValidation class; the two Button controls in our case. When those raise click events, we start at the triggering element and use <a href="http://docs.jquery.com/Traversing/parents#expr" target="_blank">the parents() traversal method</a> to search upward for the nearest parent flagged as a validationGroup.</p>
<p>In this example, that will find a reference to the fieldset which contains the Button control that triggers the click event (e.g. if the user clicks the Login Button, then $group will store a reference to the first fieldset element).</p>
<p>With that reference to the the logical form requiring validation, <a href="http://docs.jquery.com/Traversing/find#expr" target="_blank">jQuery’s find() traversal method</a> allows us to select a set of all the input elements within just that region of the page. Note that this will also include the Button control that triggered the event, but since the valid() method returns <em>true</em> for elements that don’t have validation rules configured, this doesn’t cause a problem.</p>
<p>From there, it’s straightforward to iterate over the appropriate input elements and validate each independently, using <a href="http://encosia.com/2009/11/04/using-jquery-validation-with-asp-net-webforms/" target="_blank">the valid() trick covered in the last post</a>.</p>
<h3>Handling the enter key</h3>
<p>At this point, everything works pretty well, so long as the user <em>clicks</em> on the Button controls to submit the logical forms. Unfortunately, things fall apart if the user triggers form submission by pressing enter in one of the form fields.</p>
<p>One way to fix that would be to handle the form’s onsubmit event, determine if an element flagged with the causesValidation class triggered the submission, and then run through our validation first. That’s perfectly valid, but <strong>I avoid that because it tends to clash with other functionality that handles the event</strong>; <a href="http://jquery.malsup.com/form/" target="_blank">the jQuery form plugin</a> for example.</p>
<p>The alternative that I prefer is to handle a validated field’s onkeydown event. That way, if the element does need to trigger validation, it can do so early, and get out of the way quickly otherwise.</p>
<p>Using jQuery’s cross-browser normalized event object, testing for the enter key is not difficult at all. When handling keyboard related events, one property of that object is <strong>keyCode</strong>. This property will contain the ASCII character code of the key which triggered the event. In the case of the enter key, that keyCode is <strong>13</strong>.</p>
<p>That in mind, this is a first iteration of adding enter key handling to our existing validation code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Select any input[type=text] elements within a validation group</span>
<span style="color: #006600; font-style: italic;">//  and attach keydown handlers to all of them.</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.validationGroup :text'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keydown</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Only execute validation if the key pressed was enter.</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Validation code goes here.</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Whether the form is submitted by clicking a button or hitting the enter key within one of our validation groups’ text fields, the appropriate inputs will be validated, error messages displayed if necessary, and <strong>submission will only continue if the form is valid</strong>.</p>
<h3>Refactoring to eliminate duplication</h3>
<p>After adding the keydown handler, everything works great, but it’s no good to have that validation code duplicated for both the click and keydown handlers. By passing around a reference to the jQuery event object, we can reuse the same validation code for both event types and make the code much more concise:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Initialize validation on the entire ASP.NET form.</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#form1&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">validate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// This prevents validation from running on every</span>
    <span style="color: #006600; font-style: italic;">//  form submission by default.</span>
    onsubmit<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Search for controls marked with the causesValidation flag </span>
  <span style="color: #006600; font-style: italic;">//  that are contained anywhere within elements marked as </span>
  <span style="color: #006600; font-style: italic;">//  validationGroups, and wire their click event up.</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.validationGroup .causesValidation'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span>ValidateAndSubmit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Select any input[type=text] elements within a validation group</span>
  <span style="color: #006600; font-style: italic;">//  and attach keydown handlers to all of them.</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.validationGroup :text'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keydown</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Only execute validation if the key pressed was enter.</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">keyCode</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      ValidateAndSubmit<span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> ValidateAndSubmit<span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Ascend from the button that triggered this click event </span>
  <span style="color: #006600; font-style: italic;">//  until we find a container element flagged with </span>
  <span style="color: #006600; font-style: italic;">//  .validationGroup and store a reference to that element.</span>
  <span style="color: #003366; font-weight: bold;">var</span> $group <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>evt.<span style="color: #660066;">currentTarget</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parents</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.validationGroup'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> isValid <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Descending from that .validationGroup element, find any input</span>
  <span style="color: #006600; font-style: italic;">//  elements within it, iterate over them, and run validation on </span>
  <span style="color: #006600; font-style: italic;">//  each of them.</span>
  $group.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">':input'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">valid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      isValid <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// If any fields failed validation, prevent the button's click </span>
  <span style="color: #006600; font-style: italic;">//  event from triggering form submission.</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isValid<span style="color: #009900;">&#41;</span>
    evt.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>First, the validation code is refactored into a separate function: <strong>Validate</strong>.</p>
<p>Since it needs the ability to conditionally call preventDefault in order to stop form submission, the function accepts the event handlers’ jQuery event object as a parameter.</p>
<p>In fact, because $(this) is a reasonable place to begin the parents() traversal for either event that may call the method, very little refactoring is necessary.</p>
<p>The one thing that may seem strange is that the Validate function is being passed as a click handler without any parameters. <strong>The reason that this works is because the Validate function is defined with the same signature that jQuery expects</strong>. Because of that alignment, Validate will automatically be provided with the same event object that we’ve been using in anonymous callback functions thus far.</p>
<h3>Calculated readability</h3>
<p>Note that I attached keydown handlers to <em>all</em> of the text inputs within a validation group, <strong>regardless of whether or not they are actually validated fields</strong>. Similarly, you may have noticed that the click handler finds every input element within its validation group, even if those inputs aren’t marked for validation. This may seem like an oversight, but it’s an intended readability compromise.</p>
<p>You <em>could</em> modify the selector to be more precise, selecting only fields flagged with validation classes (e.g. <em>required</em>, <em>email</em>, <em>number</em>, etc). However, this gets messy when you consider <a href="http://docs.jquery.com/Plugins/Validation#List_of_built-in_Validation_methods" rel="nofollow" target="_blank">the wide variety of classes that are valid for tagging elements with jQuery validation functionality</a>.</p>
<p>Rather than be precisely specific, I rely on the fact that <strong>jQuery validation’s valid() method returns <em>true</em> for elements which are not configured for validation</strong>. So, even if we do end up checking the validation status of a few irrelevant input fields, it won’t adversely impact the outcome of the validation process.</p>
<p>There are performance penalties to performing validation on these unnecessary elements, but it is negligible for a reasonably sized form. The ancillary inputs would have to number in the thousands before the penalty were noticeable, at which no one will probably ever successfully complete it anyway!</p>
<h3>Conclusion</h3>
<p>There are even more enhancements to be had, but I think this brings the solution to a point that it’s useful. With multiple logical forms handled and the perennially pesky enter key tamed, the majority of use cases should be covered.</p>
<p>The most troublesome issue still remaining is that <strong>care should be taken to avoid nesting container elements with the validationGroup class on them</strong>. Otherwise, the Validate() function will search “too high” and possibly hinge validation on input fields that are not intended. It’s an edge case (fixable if necessary), but something to keep in mind.</p>
<p>Another edge case is that, unlike the ASP.NET Validators, <strong>these validation groups can’t overlap</strong>. For my own use, this has never been an issue. I’m curious if that’s a real-world problem for any of you.</p>
<p>Finally, an entirely different approach well worth considering is <a href="http://john.rummell.info/john/blog/" target="_blank">John Rummell</a>’s <a href="http://xvalwebforms.codeplex.com/" rel="nofollow" target="_blank">xVal for Webforms</a>. Using Data Annotations to specify validation rules is gaining a lot of popularity, so it’s worth investigating options like this one. At the minimum, it will help you be more familiar with how validation is handled in ASP.NET MVC.</p>
<p>Hope that helps. Be sure to take a look at the source download to see everything pulled together and one extra usability feature that I didn’t have time to cover.</p>
<h3>Source</h3>
<p><a href="http://encosia.com/source/WebForms-jq-validation-p2.zip" title="WebForms-jq-validation-p2.zip"><img src="http://encosia.com/blog/wp-content/uploads/2009/11/download-WebForms-jq-validation-p2.png" width="492" height="46" alt="Download WebForms-jq-validation-p2.zip" /></a></p>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/11/24/asp-net-webforms-validation-groups-with-jquery-validation/">Emulate ASP.NET validation groups with jQuery validation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2009/11/24/asp-net-webforms-validation-groups-with-jquery-validation/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Using jQuery validation with ASP.NET WebForms</title>
		<link>http://encosia.com/2009/11/04/using-jquery-validation-with-asp-net-webforms/</link>
		<comments>http://encosia.com/2009/11/04/using-jquery-validation-with-asp-net-webforms/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 09:57:24 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/?p=939</guid>
		<description><![CDATA[
You’ve probably noticed that Jörn Zaefferer’s jQuery validation plugin has been gaining momentum in the ASP.NET community lately. Between Microsoft’s implied endorsement via ASP.NET MVC 2.0 integration and the plugin’s recent inclusion on the Microsoft AJAX CDN, adoption is only increasing. Unfortunately for those who don’t or can’t use ASP.NET MVC yet, using the validation [...]<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/11/04/using-jquery-validation-with-asp-net-webforms/">Using jQuery validation with ASP.NET WebForms</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img style="border: 1px solid #333;" title="Validation Sticker" border="0" alt="Validation Sticker" src="http://encosia.com/blog/wp-content/uploads/2009/11/validation-sticker.jpg" width="490" height="138" /></p>
<p>You’ve probably noticed that Jörn Zaefferer’s <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" target="_blank">jQuery validation plugin</a> has been gaining momentum in the ASP.NET community lately. Between Microsoft’s implied endorsement via <a href="http://haacked.com/archive/2009/10/01/asp.net-mvc-preview-2-released.aspx" target="_blank">ASP.NET MVC 2.0 integration</a> and <a href="http://www.asp.net/ajax/CDN/#5" target="_blank">the plugin’s recent inclusion on the Microsoft AJAX CDN</a>, adoption is only increasing. Unfortunately for those who don’t or can’t use ASP.NET MVC yet, using the validation plugin within WebForms applications can be tricky.</p>
<p>Because the WebForms Postback model requires that the entire page be contained within a single form element, form submissions that shouldn’t trigger validation are likely. ASP.NET’s built-in validation controls solve this with ValidationGroups and the CausesValidation property, but that doesn’t help if you’d prefer to use the jQuery validation plugin.</p>
<p>However, there <em>are</em> a couple relatively easy workarounds that make it possible to use the jQuery validation plugin on WebForms pages, without re-architecting the page or its forms. In this post, I’ll show you <strong>why the WebForms page structure is a problem</strong>, how to <strong>make jQuery validation work with it</strong>, and <strong>an example of implementing those workarounds</strong>.</p>
<p><em>Note: I want to preface this by saying that you should never rely entirely on client-side validation. The jQuery validation plugin can be a great replacement for the client-side part of the ASP.NET Validators, but it is not a complete replacement on its own. Use responsibly!</em></p>
<h3>&lt;form&gt; over function</h3>
<p>When it comes to using jQuery validation, <strong>the trouble with WebForms is that it requires all of the ASP.NET controls on a page to be contained within a single form element</strong>. That doesn’t lead to any problems in simple demos, but things are more complicated when it comes to real-world pages. They often require multiple logical forms on the same page, and that’s where the problems start.</p>
<p>For example, consider the common scenario of having both a login form and a customer information form on the same page. We’ve probably all seen something like this before:</p>

<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #060; font-weight: bold;">&lt;</span>form id<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;form1&quot;</span> runat<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;server&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>
  <span style="color: #060; font-weight: bold;">&lt;</span>fieldset<span style="color: #060; font-weight: bold;">&gt;</span>
    <span style="color: #060; font-weight: bold;">&lt;</span>legend<span style="color: #060; font-weight: bold;">&gt;</span>Returning customer<span style="color: #060; font-weight: bold;">?</span>  Login here<span style="color: #060; font-weight: bold;">&lt;/</span>legend<span style="color: #060; font-weight: bold;">&gt;</span>
&nbsp;
    <span style="color: #060; font-weight: bold;">&lt;</span>label <span style="color: #909; font-weight: bold;">for</span><span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Username&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>Email<span style="color: #060; font-weight: bold;">:&lt;/</span>label<span style="color: #060; font-weight: bold;">&gt;</span>
    <span style="color: #060; font-weight: bold;">&lt;</span>asp<span style="color: #060; font-weight: bold;">:</span>TextBox runat<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;server&quot;</span> ID<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Username&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
&nbsp;
    <span style="color: #060; font-weight: bold;">&lt;</span>label <span style="color: #909; font-weight: bold;">for</span><span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Password&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>Password<span style="color: #060; font-weight: bold;">:&lt;/</span>label<span style="color: #060; font-weight: bold;">&gt;</span>
    <span style="color: #060; font-weight: bold;">&lt;</span>asp<span style="color: #060; font-weight: bold;">:</span>TextBox runat<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;server&quot;</span> ID<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Password&quot;</span> TextMode<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Password&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
&nbsp;
    <span style="color: #060; font-weight: bold;">&lt;</span>asp<span style="color: #060; font-weight: bold;">:</span>Button runat<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;server&quot;</span> ID<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Login&quot;</span> Text<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Login&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
  <span style="color: #060; font-weight: bold;">&lt;/</span>fieldset<span style="color: #060; font-weight: bold;">&gt;</span>
&nbsp;
  <span style="color: #060; font-weight: bold;">&lt;</span>fieldset id<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;BillingInfo&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>
    <span style="color: #060; font-weight: bold;">&lt;</span>legend<span style="color: #060; font-weight: bold;">&gt;</span>New customer<span style="color: #060; font-weight: bold;">?</span>  Provide the following<span style="color: #060; font-weight: bold;">&lt;/</span>legend<span style="color: #060; font-weight: bold;">&gt;</span>
&nbsp;
    <span style="color: #060; font-weight: bold;">&lt;</span>label <span style="color: #909; font-weight: bold;">for</span><span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;FirstName&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>First Name<span style="color: #060; font-weight: bold;">:&lt;/</span>label<span style="color: #060; font-weight: bold;">&gt;</span>
    <span style="color: #060; font-weight: bold;">&lt;</span>asp<span style="color: #060; font-weight: bold;">:</span>TextBox runat<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;server&quot;</span> ID<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;FirstName&quot;</span> CssClass<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;required&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
&nbsp;
    <span style="color: #060; font-weight: bold;">&lt;</span>label <span style="color: #909; font-weight: bold;">for</span><span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;LastName&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>Last Name<span style="color: #060; font-weight: bold;">:&lt;/</span>label<span style="color: #060; font-weight: bold;">&gt;</span>
    <span style="color: #060; font-weight: bold;">&lt;</span>asp<span style="color: #060; font-weight: bold;">:</span>TextBox runat<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;server&quot;</span> ID<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;LastName&quot;</span> CssClass<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;required&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
&nbsp;
    <span style="color: #060; font-weight: bold;">&lt;</span>label <span style="color: #909; font-weight: bold;">for</span><span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Address&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>Address<span style="color: #060; font-weight: bold;">:&lt;/</span>label<span style="color: #060; font-weight: bold;">&gt;</span>
    <span style="color: #060; font-weight: bold;">&lt;</span>asp<span style="color: #060; font-weight: bold;">:</span>TextBox runat<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;server&quot;</span> ID<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Address&quot;</span> CssClass<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;required&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
&nbsp;
    <span style="color: #060; font-weight: bold;">&lt;</span>label <span style="color: #909; font-weight: bold;">for</span><span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;City&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>City<span style="color: #060; font-weight: bold;">:&lt;/</span>label<span style="color: #060; font-weight: bold;">&gt;</span>
    <span style="color: #060; font-weight: bold;">&lt;</span>asp<span style="color: #060; font-weight: bold;">:</span>TextBox runat<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;server&quot;</span> ID<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;City&quot;</span> CssClass<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;required&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
&nbsp;
    <span style="color: #060; font-weight: bold;">&lt;</span>label <span style="color: #909; font-weight: bold;">for</span><span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;State&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>State<span style="color: #060; font-weight: bold;">:&lt;/</span>label<span style="color: #060; font-weight: bold;">&gt;</span>
    <span style="color: #060; font-weight: bold;">&lt;</span>asp<span style="color: #060; font-weight: bold;">:</span>TextBox runat<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;server&quot;</span> ID<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;State&quot;</span> CssClass<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;required&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
&nbsp;
    <span style="color: #060; font-weight: bold;">&lt;</span>label <span style="color: #909; font-weight: bold;">for</span><span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Zip&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>Zip<span style="color: #060; font-weight: bold;">:&lt;/</span>label<span style="color: #060; font-weight: bold;">&gt;</span>
    <span style="color: #060; font-weight: bold;">&lt;</span>asp<span style="color: #060; font-weight: bold;">:</span>TextBox runat<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;server&quot;</span> ID<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Zip&quot;</span> CssClass<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;required&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
&nbsp;
    <span style="color: #060; font-weight: bold;">&lt;</span>asp<span style="color: #060; font-weight: bold;">:</span>Button runat<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;server&quot;</span> ID<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Order&quot;</span> Text<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Submit Order&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
  <span style="color: #060; font-weight: bold;">&lt;/</span>fieldset<span style="color: #060; font-weight: bold;">&gt;</span>
<span style="color: #060; font-weight: bold;">&lt;/</span>form<span style="color: #060; font-weight: bold;">&gt;</span></pre></div></div>

<p>In most web frameworks, you would divide both logical forms into separate form elements, but WebForms requires both to remain joined within its single form element. This means that  <strong>clicking either of the Button controls will submit both logical forms together.</strong></p>
<p>Once applied to a form through <a href="http://docs.jquery.com/Plugins/Validation#Example" rel="nofollow" target="_blank">its default usage</a>, the jQuery validation plugin will attempt to validate all of the elements on that form <em>any time it is submitted</em>. That automation is usually handy, but it means <strong>users trying to submit our login form will be denied due to validation failing on the unrelated fields below</strong>.</p>
<p><img style="border: 1px solid #333;" src="http://encosia.com/blog/wp-content/uploads/2009/11/cross-validation-issue.jpg" width="490" height="416" /></p>
<p>Since using separate form elements containing WebForms controls isn’t realistic, we need to tackle this on the client-side and find a way to make jQuery validation more WebForms-friendly.</p>
<h3>Taming jQuery validation</h3>
<p>To remedy this problem, we first need to prevent the jQuery validation plugin from automatically triggering on every form submission. The initializer’s <strong>onsubmit</strong> property allows us to do just that:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Initialize validation on the entire ASP.NET form</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#form1&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">validate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// This prevents validation from running on every</span>
    <span style="color: #006600; font-style: italic;">//  form submission by default.</span>
    onsubmit<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That fixes our problem of the login form triggering unwanted validation in the form below, but it creates another issue. Now, <em>neither</em> of the forms will validate when submitted.</p>
<h3>Taking control with on-demand validation</h3>
<p>Instead of relying on the plugin to automatically validate form submissions, you may also use a less widely known method for triggering the validation on-demand. When added to a page, one of the new methods that jQuery validation exposes on the jQuery object is <strong>valid()</strong>.</p>
<p>When <a href="http://docs.jquery.com/Plugins/Validation/valid" rel="nofollow" target="_blank">valid()</a> is called on the jQuery object returned from selecting a “validated” form element, it will trigger validation on every field within the form and return a Boolean value indicating whether or not the form is valid.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#form1&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">validate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
    onsubmit<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#Order&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Validate the form and retain the result.</span>
    <span style="color: #003366; font-weight: bold;">var</span> isValid <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#form1&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">valid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// If the form didn't validate, prevent the</span>
    <span style="color: #006600; font-style: italic;">//  form submission.</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>isValid<span style="color: #009900;">&#41;</span>
      evt.<span style="color: #660066;">preventDefault</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>At first glance, this code might look incomplete to you. We care about more than just preventing form submissions when the form fails validation; we must also indicate the validation errors to the user.</p>
<p>Fortunately, <strong>the valid() method has the very useful side effect of displaying the plugin’s configured validation errors</strong> for any fields it finds to fail validation.</p>
<p>From the user’s perspective, this implementation is the same as the original one using the default usage. This method just happens to also have the added benefit of actually allowing returning users to log in.</p>
<h3>To be continued…</h3>
<p>This solution is a good start, but has (at least) two flaws.</p>
<p>First, it doesn’t handle keyboard triggered form submissions. <strong>What happens if the user hits the enter key in one of the TextBoxes</strong>?</p>
<p>Second, <strong>what if we want to also validate the login form</strong>? If validation rules are added to that form’s fields, we’ll have exactly the opposite problem as what we started with. Valid submissions in the lower form will be prevented by validation failures on the upper form.</p>
<p>For solutions to both of those problems, be sure to read my followup post: <a href="http://encosia.com/2009/11/24/asp-net-webforms-validation-groups-with-jquery-validation/">Emulate ASP.NET WebForms validation groups with jQuery validation</a>.</p>
<h3>Download the Source</h3>
<p><a href="/source/WebForms-jq-validation.zip"><img src="http://encosia.com/blog/wp-content/uploads/2009/11/download-webforms-jq-validation.png" width="492" height="46" alt="Download WebForms-jq-validation.zip" /></a></p>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/11/04/using-jquery-validation-with-asp-net-webforms/">Using jQuery validation with ASP.NET WebForms</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2009/11/04/using-jquery-validation-with-asp-net-webforms/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Do you know about this undocumented Google CDN feature?</title>
		<link>http://encosia.com/2009/10/11/do-you-know-about-this-undocumented-google-cdn-feature/</link>
		<comments>http://encosia.com/2009/10/11/do-you-know-about-this-undocumented-google-cdn-feature/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 03:26:41 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[UI]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/?p=912</guid>
		<description><![CDATA[By now, you probably already know that Google hosts jQuery on its AJAX APIs CDN, free of charge. As I’ve discussed here in the past, I’m a big fan of using their CDN to achieve decreased latency, increased parallelism, and better caching.
If you’ve explored the AJAX APIs documentation a bit, you may know that jQuery [...]<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/10/11/do-you-know-about-this-undocumented-google-cdn-feature/">Do you know about this undocumented Google CDN feature?</a></p>
]]></description>
			<content:encoded><![CDATA[<p>By now, you probably already know that Google hosts jQuery on its AJAX APIs CDN, free of charge. As I’ve discussed here in the past, I’m a big fan of <a href="http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/" target="_blank">using their CDN to achieve <strong>decreased latency</strong>, <strong>increased parallelism</strong>, and <strong>better caching</strong></a>.</p>
<p>If you’ve explored the AJAX APIs documentation a bit, you may know that <a href="http://code.google.com/apis/ajaxlibs/documentation/index.html#jqueryUI" target="_blank">jQuery UI is also hosted on Google’s CDN</a>. Unfortunately, since jQuery UI plugins depend on a <a href="http://jqueryui.com/themeroller/" target="_blank">ThemeRoller</a> theme, using a CDN for jQuery UI isn’t as easy as with jQuery itself.</p>
<p>Or, is it?</p>
<h3>My &lt;head&gt; is in the cloud</h3>
<p>While poking around a couple months ago, I stumbled upon something that I’ve found extremely useful: <a href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/start/jquery-ui.css" target="_blank">An entire jQuery UI theme hosted on Google’s CDN</a>!</p>
<p>Not only is the theme’s CSS stylesheet there, but <strong>all 14 of the theme’s images are hosted in the correct relative location too</strong>. That means you can apply the entire theme to a page with a single CSS reference and no local files.</p>
<p>Even better, while JavaScript and CSS includes are unable to take full advantage of the increased parallelism a CDN offers, the theme’s images <em>do</em>. This makes loading the theme from Google’s CDN particularly effective.</p>
<h3>Using it</h3>
<p>Using this on your own pages couldn’t be easier. There are no files to download, no paths to worry about, and no configuration is required. Just a reference to <a href="http://code.google.com/apis/ajaxlibs/documentation/#jquery" rel="nofollow" target="_blank">jQuery</a>, <a href="http://code.google.com/apis/ajaxlibs/documentation/#jqueryUI" rel="nofollow" target="_blank">jQuery UI</a>, and the ThemeRoller theme you want to use will is all you need.</p>
<p>For example, if you wanted to build a quick demo of the jQuery UI Tabs plugin, use these references in the head of your page:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #0bd;">&lt;!DOCTYPE html&gt;</span>
<span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #808080; font-style: italic;">&lt;!-- To avoid horizontal scrolling in this code listing. --&gt;</span>
  <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">base</span> <span style="color: #006;">href</span><span style="color: #66cc66;">=</span><span style="color: #f00;">&quot;http://ajax.googleapis.com/&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- Reference the theme's stylesheet on the Google CDN --&gt;</span>
  <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">link</span> <span style="color: #006;">href</span><span style="color: #66cc66;">=</span><span style="color: #f00;">&quot;/ajax/libs/jqueryui/1.7.2/themes/start/jquery-ui.css&quot;</span></span>
<span style="color: #090;">        <span style="color: #006;">type</span><span style="color: #66cc66;">=</span><span style="color: #f00;">&quot;text/css&quot;</span> <span style="color: #006;">rel</span><span style="color: #66cc66;">=</span><span style="color: #f00;">&quot;Stylesheet&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- Reference jQuery and jQuery UI from the CDN. Remember</span>
<span style="color: #808080; font-style: italic;">       that the order of these two elements is important --&gt;</span>
  <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">script</span> <span style="color: #006;">src</span><span style="color: #66cc66;">=</span><span style="color: #f00;">&quot;/ajax/libs/jquery/1.3.2/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">script</span>&gt;</span>
  <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">script</span> <span style="color: #006;">src</span><span style="color: #66cc66;">=</span><span style="color: #f00;">&quot;/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">script</span>&gt;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- Initialize the tabs when the document is ready --&gt;</span>
  <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">script</span> <span style="color: #006;">type</span><span style="color: #66cc66;">=</span><span style="color: #f00;">&quot;text/javascript&quot;</span>&gt;</span>
    $(document).ready(function() {
      // See the jQuery UI Tabs documentation for
      //  more information about how this works.
      $('#tabs').tabs();
    });
  <span style="color: #090;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #090;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">head</span>&gt;</span></pre></div></div>

<p><em>Note: You shouldn’t use the &lt;base&gt; tag like this in your pages. It affects all links on the page, not just those in the &lt;head&gt;. I’m just using it here to avoid horizontal scrolling (the bane of my existence when posting code here).</em></p>
<p>Then, just a bit of corresponding markup in the body of the document (<a href="http://jqueryui.com/demos/tabs/" target="_blank">see the jQuery UI Tabs documentation</a> for specifics):</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">body</span>&gt;</span>
  <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">div</span> <span style="color: #006;">id</span><span style="color: #66cc66;">=</span><span style="color: #f00;">&quot;tabs&quot;</span>&gt;</span>
    <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">ul</span>&gt;</span>
      <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000; font-weight: bold;">a</span> <span style="color: #006;">href</span><span style="color: #66cc66;">=</span><span style="color: #f00;">&quot;#tab-1&quot;</span>&gt;</span>Tab 1<span style="color: #090;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000; font-weight: bold;">a</span> <span style="color: #006;">href</span><span style="color: #66cc66;">=</span><span style="color: #f00;">&quot;#tab-2&quot;</span>&gt;</span>Tab 2<span style="color: #090;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">li</span>&gt;</span>
      <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">li</span>&gt;&lt;<span style="color: #000; font-weight: bold;">a</span> <span style="color: #006;">href</span><span style="color: #66cc66;">=</span><span style="color: #f00;">&quot;#tab-3&quot;</span>&gt;</span>Tab 3<span style="color: #090;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #090;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">ul</span>&gt;</span>
&nbsp;
    <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">div</span> <span style="color: #006;">id</span><span style="color: #66cc66;">=</span><span style="color: #f00;">&quot;tab-1&quot;</span>&gt;</span>
      <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">p</span>&gt;</span>These tabs were created with JavaScript, CSS, and 
        images hosted on Google's AJAX APIs CDN.<span style="color: #090;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">p</span>&gt;</span>
&nbsp;
      <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">p</span>&gt;</span>Thanks, Google!<span style="color: #090;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">p</span>&gt;</span>
    <span style="color: #090;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">div</span> <span style="color: #006;">id</span><span style="color: #66cc66;">=</span><span style="color: #f00;">&quot;tab-2&quot;</span>&gt;</span>
      <span style="color: #808080; font-style: italic;">&lt;!-- Tab 2's content goes here. --&gt;</span>
    <span style="color: #090;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #090;">&lt;<span style="color: #000; font-weight: bold;">div</span> <span style="color: #006;">id</span><span style="color: #66cc66;">=</span><span style="color: #f00;">&quot;tab-3&quot;</span>&gt;</span>
      <span style="color: #808080; font-style: italic;">&lt;!-- Tab 3's content goes here. --&gt;</span>
    <span style="color: #090;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #090;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #090;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #090;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000; font-weight: bold;">html</span>&gt;</span></pre></div></div>

<p>That HTML (without a single file or image hosted locally) results in this:</p>
<p><img alt="tabs-example" src="http://encosia.com/blog/wp-content/uploads/2009/10/tabs-example.png" width="492" height="206" /></p>
<p>Don’t like the theme in my example? Don’t worry, because <strong>all 24 of the standard ThemeRoller presets are also hosted on the CDN</strong>. See the end of this post for a full listing.</p>
<h3>Nothing’s perfect</h3>
<p>There are a couple of potential issues when using these CDN hosted themes.</p>
<p>First, <strong>these themes aren’t minified</strong>. Minification shaves about 20% off the size of an average ThemeRoller theme’s CSS, which is definitely worthwhile. Hopefully, minified versions will be available at some point (assuming I didn’t miss ones that may already be hiding there somewhere). In the meantime, Google does properly gzip compress them though, which makes the difference less significant.</p>
<p>Second, if you normally customize ThemeRoller’s CSS or images manually, this probably isn’t for you. Lacking control over the base CSS style is something that you can work around, but isn’t worth the complexity and extra HTTP requests.</p>
<p>However, <strong>you can still reference the CDN’s images from custom CSS</strong>, by using absolute paths.</p>
<h3>Conclusion</h3>
<p>Overall, this seemingly small feature has been surprisingly useful in my day-to-day development. While it’s technically not very difficult to download and set up local ThemeRoller themes, there’s more friction to it than I care for. <strong>Boiling the entire process down to a single CSS reference removes all of that friction</strong>.</p>
<p>Even if you don’t like the idea of relying on a CDN hosted theme for production sites, <strong>this is great for prototyping</strong>. <a href="http://encosia.com/2009/09/21/updated-see-how-i-used-firebug-to-learn-jquery/">Anything that makes prototyping faster is a big win</a>, because it allows you to try more ideas in the same amount of time.</p>
<p>What do you think? Does this sound useful to you? Are you comfortable leaning on Google’s CDN for your entire jQuery UI theme? Would you use this in production?</p>
<h3 id="fullListing">Full Theme Listing</h3>
<p><strong>The URLs below reference jQuery UI v1.7.2 themes</strong>.  If 1.7.2 isn&#8217;t the latest version at the time that you&#8217;re reading this, you should be able to replace 1.7.2 in the URL with the current version and find a current theme hosted on the CDN.</p>
<p>Click any of the thumbnails to view that theme on ThemeRoller.</p>
<p>Click any of the input fields to select the full URL to the theme&#8217;s CDN hosted CSS file, ready for copy/pasting into your page.</p>
<p><noscript>Attention RSS Readers:  You will probably need to view this full post in your browser to see the input fields. <a href="http://encosia.com/912#fullListing" target="_blank">Click here to open the post and skip directly at this point in the post</a>.</noscript></p>
<table width="492">
<tr>
<td align="center"><strong>UI Lightness</strong></td>
<td align="center"><strong>UI Darkness</strong></td>
<tr valign="top">
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Trebuchet+MS,+Tahoma,+Verdana,+Arial,+sans-serif&#038;fwDefault=bold&#038;fsDefault=1.1em&#038;cornerRadius=4px&#038;bgColorHeader=f6a828&#038;bgTextureHeader=12_gloss_wave.png&#038;bgImgOpacityHeader=35&#038;borderColorHeader=e78f08&#038;fcHeader=ffffff&#038;iconColorHeader=ffffff&#038;bgColorContent=eeeeee&#038;bgTextureContent=03_highlight_soft.png&#038;bgImgOpacityContent=100&#038;borderColorContent=dddddd&#038;fcContent=333333&#038;iconColorContent=222222&#038;bgColorDefault=f6f6f6&#038;bgTextureDefault=02_glass.png&#038;bgImgOpacityDefault=100&#038;borderColorDefault=cccccc&#038;fcDefault=1c94c4&#038;iconColorDefault=ef8c08&#038;bgColorHover=fdf5ce&#038;bgTextureHover=02_glass.png&#038;bgImgOpacityHover=100&#038;borderColorHover=fbcb09&#038;fcHover=c77405&#038;iconColorHover=ef8c08&#038;bgColorActive=ffffff&#038;bgTextureActive=02_glass.png&#038;bgImgOpacityActive=65&#038;borderColorActive=fbd850&#038;fcActive=eb8f00&#038;iconColorActive=ef8c08&#038;bgColorHighlight=ffe45c&#038;bgTextureHighlight=03_highlight_soft.png&#038;bgImgOpacityHighlight=75&#038;borderColorHighlight=fed22f&#038;fcHighlight=363636&#038;iconColorHighlight=228ef1&#038;bgColorError=b81900&#038;bgTextureError=08_diagonals_thick.png&#038;bgImgOpacityError=18&#038;borderColorError=cd0a0a&#038;fcError=ffffff&#038;iconColorError=ffd27a&#038;bgColorOverlay=666666&#038;bgTextureOverlay=08_diagonals_thick.png&#038;bgImgOpacityOverlay=20&#038;opacityOverlay=50&#038;bgColorShadow=000000&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=10&#038;opacityShadow=20&#038;thicknessShadow=5px&#038;offsetTopShadow=-5px&#038;offsetLeftShadow=-5px&#038;cornerRadiusShadow=5px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/ui-lightness-thumb.PNG" width="194" height="178" /></a></td>
<td align="center"><a href="http://jqueryui.com/themeroller/#ffDefault=Segoe+UI%2C+Arial%2C+sans-serif&#038;fwDefault=bold&#038;fsDefault=1.1em&#038;cornerRadius=6px&#038;bgColorHeader=333333&#038;bgTextureHeader=12_gloss_wave.png&#038;bgImgOpacityHeader=25&#038;borderColorHeader=333333&#038;fcHeader=ffffff&#038;iconColorHeader=ffffff&#038;bgColorContent=000000&#038;bgTextureContent=05_inset_soft.png&#038;bgImgOpacityContent=25&#038;borderColorContent=666666&#038;fcContent=ffffff&#038;iconColorContent=cccccc&#038;bgColorDefault=555555&#038;bgTextureDefault=02_glass.png&#038;bgImgOpacityDefault=20&#038;borderColorDefault=666666&#038;fcDefault=eeeeee&#038;iconColorDefault=cccccc&#038;bgColorHover=0078a3&#038;bgTextureHover=02_glass.png&#038;bgImgOpacityHover=40&#038;borderColorHover=59b4d4&#038;fcHover=ffffff&#038;iconColorHover=ffffff&#038;bgColorActive=f58400&#038;bgTextureActive=05_inset_soft.png&#038;bgImgOpacityActive=30&#038;borderColorActive=ffaf0f&#038;fcActive=ffffff&#038;iconColorActive=222222&#038;bgColorHighlight=eeeeee&#038;bgTextureHighlight=03_highlight_soft.png&#038;bgImgOpacityHighlight=80&#038;borderColorHighlight=cccccc&#038;fcHighlight=2e7db2&#038;iconColorHighlight=4b8e0b&#038;bgColorError=ffc73d&#038;bgTextureError=02_glass.png&#038;bgImgOpacityError=40&#038;borderColorError=ffb73d&#038;fcError=111111&#038;iconColorError=a83300&#038;bgColorOverlay=5c5c5c&#038;bgTextureOverlay=01_flat.png&#038;bgImgOpacityOverlay=50&#038;opacityOverlay=80&#038;bgColorShadow=cccccc&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=30&#038;opacityShadow=60&#038;thicknessShadow=7px&#038;offsetTopShadow=-7px&#038;offsetLeftShadow=-7px&#038;cornerRadiusShadow=8px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/ui-darkness-thumb.png" width="194" height="160" /></a></td>
</tr>
<tr>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-darkness/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
</tr>
<tr>
<td colspan="2">
<hr /></td>
</tr>
<tr>
<td align="center"><strong>Smoothness</strong></td>
<td align="center"><strong>Start</strong></td>
<tr valign="top">
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Verdana,Arial,sans-serif&#038;fwDefault=normal&#038;fsDefault=1.1em&#038;cornerRadius=4px&#038;bgColorHeader=cccccc&#038;bgTextureHeader=03_highlight_soft.png&#038;bgImgOpacityHeader=75&#038;borderColorHeader=aaaaaa&#038;fcHeader=222222&#038;iconColorHeader=222222&#038;bgColorContent=ffffff&#038;bgTextureContent=01_flat.png&#038;bgImgOpacityContent=75&#038;borderColorContent=aaaaaa&#038;fcContent=222222&#038;iconColorContent=222222&#038;bgColorDefault=e6e6e6&#038;bgTextureDefault=02_glass.png&#038;bgImgOpacityDefault=75&#038;borderColorDefault=d3d3d3&#038;fcDefault=555555&#038;iconColorDefault=888888&#038;bgColorHover=dadada&#038;bgTextureHover=02_glass.png&#038;bgImgOpacityHover=75&#038;borderColorHover=999999&#038;fcHover=212121&#038;iconColorHover=454545&#038;bgColorActive=ffffff&#038;bgTextureActive=02_glass.png&#038;bgImgOpacityActive=65&#038;borderColorActive=aaaaaa&#038;fcActive=212121&#038;iconColorActive=454545&#038;bgColorHighlight=fbf9ee&#038;bgTextureHighlight=02_glass.png&#038;bgImgOpacityHighlight=55&#038;borderColorHighlight=fcefa1&#038;fcHighlight=363636&#038;iconColorHighlight=2e83ff&#038;bgColorError=fef1ec&#038;bgTextureError=02_glass.png&#038;bgImgOpacityError=95&#038;borderColorError=cd0a0a&#038;fcError=cd0a0a&#038;iconColorError=cd0a0a&#038;bgColorOverlay=aaaaaa&#038;bgTextureOverlay=01_flat.png&#038;bgImgOpacityOverlay=0&#038;opacityOverlay=30&#038;bgColorShadow=aaaaaa&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=0&#038;opacityShadow=30&#038;thicknessShadow=8px&#038;offsetTopShadow=-8px&#038;offsetLeftShadow=-8px&#038;cornerRadiusShadow=8px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/smoothness-thumb.PNG" width="194" height="160" /></a></td>
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Verdana%2CArial%2Csans-serif&#038;fwDefault=normal&#038;fsDefault=1.1em&#038;cornerRadius=5px&#038;bgColorHeader=2191c0&#038;bgTextureHeader=12_gloss_wave.png&#038;bgImgOpacityHeader=75&#038;borderColorHeader=4297d7&#038;fcHeader=eaf5f7&#038;iconColorHeader=d8e7f3&#038;bgColorContent=fcfdfd&#038;bgTextureContent=06_inset_hard.png&#038;bgImgOpacityContent=100&#038;borderColorContent=a6c9e2&#038;fcContent=222222&#038;iconColorContent=0078ae&#038;bgColorDefault=0078ae&#038;bgTextureDefault=02_glass.png&#038;bgImgOpacityDefault=45&#038;borderColorDefault=77d5f7&#038;fcDefault=ffffff&#038;iconColorDefault=e0fdff&#038;bgColorHover=79c9ec&#038;bgTextureHover=02_glass.png&#038;bgImgOpacityHover=75&#038;borderColorHover=448dae&#038;fcHover=026890&#038;iconColorHover=056b93&#038;bgColorActive=6eac2c&#038;bgTextureActive=12_gloss_wave.png&#038;bgImgOpacityActive=50&#038;borderColorActive=acdd4a&#038;fcActive=ffffff&#038;iconColorActive=f5e175&#038;bgColorHighlight=f8da4e&#038;bgTextureHighlight=02_glass.png&#038;bgImgOpacityHighlight=55&#038;borderColorHighlight=fcd113&#038;fcHighlight=915608&#038;iconColorHighlight=f7a50d&#038;bgColorError=e14f1c&#038;bgTextureError=12_gloss_wave.png&#038;bgImgOpacityError=45&#038;borderColorError=cd0a0a&#038;fcError=ffffff&#038;iconColorError=fcd113&#038;bgColorOverlay=aaaaaa&#038;bgTextureOverlay=01_flat.png&#038;bgImgOpacityOverlay=75&#038;opacityOverlay=30&#038;bgColorShadow=999999&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=55&#038;opacityShadow=45&#038;thicknessShadow=0px&#038;offsetTopShadow=5px&#038;offsetLeftShadow=5px&#038;cornerRadiusShadow=5px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/start-thumb.PNG" width="194" height="160" /></a></td>
</tr>
<tr>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/smoothness/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/start/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
</tr>
<tr>
<td colspan="2">
<hr /></td>
</tr>
<tr>
<td align="center"><strong>Redmond</strong></td>
<td align="center"><strong>Sunny</strong></td>
<tr valign="top">
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Lucida+Grande,+Lucida+Sans,+Arial,+sans-serif&#038;fwDefault=bold&#038;fsDefault=1.1em&#038;cornerRadius=5px&#038;bgColorHeader=5c9ccc&#038;bgTextureHeader=12_gloss_wave.png&#038;bgImgOpacityHeader=55&#038;borderColorHeader=4297d7&#038;fcHeader=ffffff&#038;iconColorHeader=d8e7f3&#038;bgColorContent=fcfdfd&#038;bgTextureContent=06_inset_hard.png&#038;bgImgOpacityContent=100&#038;borderColorContent=a6c9e2&#038;fcContent=222222&#038;iconColorContent=469bdd&#038;bgColorDefault=dfeffc&#038;bgTextureDefault=02_glass.png&#038;bgImgOpacityDefault=85&#038;borderColorDefault=c5dbec&#038;fcDefault=2e6e9e&#038;iconColorDefault=6da8d5&#038;bgColorHover=d0e5f5&#038;bgTextureHover=02_glass.png&#038;bgImgOpacityHover=75&#038;borderColorHover=79b7e7&#038;fcHover=1d5987&#038;iconColorHover=217bc0&#038;bgColorActive=f5f8f9&#038;bgTextureActive=06_inset_hard.png&#038;bgImgOpacityActive=100&#038;borderColorActive=79b7e7&#038;fcActive=e17009&#038;iconColorActive=f9bd01&#038;bgColorHighlight=fbec88&#038;bgTextureHighlight=01_flat.png&#038;bgImgOpacityHighlight=55&#038;borderColorHighlight=fad42e&#038;fcHighlight=363636&#038;iconColorHighlight=2e83ff&#038;bgColorError=fef1ec&#038;bgTextureError=02_glass.png&#038;bgImgOpacityError=95&#038;borderColorError=cd0a0a&#038;fcError=cd0a0a&#038;iconColorError=cd0a0a&#038;bgColorOverlay=aaaaaa&#038;bgTextureOverlay=01_flat.png&#038;bgImgOpacityOverlay=0&#038;opacityOverlay=30&#038;bgColorShadow=aaaaaa&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=0&#038;opacityShadow=30&#038;thicknessShadow=8px&#038;offsetTopShadow=-8px&#038;offsetLeftShadow=-8px&#038;cornerRadiusShadow=8px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/redmond-thumb.PNG" width="194" height="154" /></a></td>
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Segoe+UI%2C+Arial%2C+sans-serif&#038;fwDefault=bold&#038;fsDefault=1.1em&#038;cornerRadius=8px&#038;bgColorHeader=817865&#038;bgTextureHeader=12_gloss_wave.png&#038;bgImgOpacityHeader=45&#038;borderColorHeader=494437&#038;fcHeader=ffffff&#038;iconColorHeader=fadc7a&#038;bgColorContent=feeebd&#038;bgTextureContent=03_highlight_soft.png&#038;bgImgOpacityContent=100&#038;borderColorContent=8e846b&#038;fcContent=383838&#038;iconColorContent=d19405&#038;bgColorDefault=fece2f&#038;bgTextureDefault=12_gloss_wave.png&#038;bgImgOpacityDefault=60&#038;borderColorDefault=d19405&#038;fcDefault=4c3000&#038;iconColorDefault=3d3d3d&#038;bgColorHover=ffdd57&#038;bgTextureHover=12_gloss_wave.png&#038;bgImgOpacityHover=70&#038;borderColorHover=a45b13&#038;fcHover=381f00&#038;iconColorHover=bd7b00&#038;bgColorActive=ffffff&#038;bgTextureActive=05_inset_soft.png&#038;bgImgOpacityActive=30&#038;borderColorActive=655e4e&#038;fcActive=0074c7&#038;iconColorActive=eb990f&#038;bgColorHighlight=fff9e5&#038;bgTextureHighlight=12_gloss_wave.png&#038;bgImgOpacityHighlight=90&#038;borderColorHighlight=eeb420&#038;fcHighlight=1f1f1f&#038;iconColorHighlight=ed9f26&#038;bgColorError=d34d17&#038;bgTextureError=07_diagonals_medium.png&#038;bgImgOpacityError=20&#038;borderColorError=ffb73d&#038;fcError=ffffff&#038;iconColorError=ffe180&#038;bgColorOverlay=5c5c5c&#038;bgTextureOverlay=01_flat.png&#038;bgImgOpacityOverlay=50&#038;opacityOverlay=80&#038;bgColorShadow=cccccc&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=30&#038;opacityShadow=60&#038;thicknessShadow=7px&#038;offsetTopShadow=-7px&#038;offsetLeftShadow=-7px&#038;cornerRadiusShadow=8px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/sunny-thumb.png" width="194" height="160" /></a></td>
</tr>
<tr>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/sunny/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
</tr>
<tr>
<td colspan="2">
<hr /></td>
</tr>
<tr>
<td align="center"><strong>Overcast</strong></td>
<td align="center"><strong>Le Frog</strong></td>
<tr valign="top">
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Trebuchet+MS%2C+Helvetica%2C+Arial%2C+sans-serif&#038;fwDefault=bold&#038;fsDefault=1.1em&#038;cornerRadius=6px&#038;bgColorHeader=dddddd&#038;bgTextureHeader=02_glass.png&#038;bgImgOpacityHeader=35&#038;borderColorHeader=bbbbbb&#038;fcHeader=444444&#038;iconColorHeader=999999&#038;bgColorContent=c9c9c9&#038;bgTextureContent=05_inset_soft.png&#038;bgImgOpacityContent=50&#038;borderColorContent=aaaaaa&#038;fcContent=333333&#038;iconColorContent=999999&#038;bgColorDefault=eeeeee&#038;bgTextureDefault=02_glass.png&#038;bgImgOpacityDefault=60&#038;borderColorDefault=cccccc&#038;fcDefault=3383bb&#038;iconColorDefault=70b2e1&#038;bgColorHover=f8f8f8&#038;bgTextureHover=02_glass.png&#038;bgImgOpacityHover=100&#038;borderColorHover=bbbbbb&#038;fcHover=599fcf&#038;iconColorHover=3383bb&#038;bgColorActive=999999&#038;bgTextureActive=06_inset_hard.png&#038;bgImgOpacityActive=75&#038;borderColorActive=999999&#038;fcActive=ffffff&#038;iconColorActive=454545&#038;bgColorHighlight=eeeeee&#038;bgTextureHighlight=01_flat.png&#038;bgImgOpacityHighlight=55&#038;borderColorHighlight=ffffff&#038;fcHighlight=444444&#038;iconColorHighlight=3383bb&#038;bgColorError=c0402a&#038;bgTextureError=01_flat.png&#038;bgImgOpacityError=55&#038;borderColorError=c0402a&#038;fcError=ffffff&#038;iconColorError=fbc856&#038;bgColorOverlay=eeeeee&#038;bgTextureOverlay=01_flat.png&#038;bgImgOpacityOverlay=0&#038;opacityOverlay=80&#038;bgColorShadow=aaaaaa&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=0&#038;opacityShadow=60&#038;thicknessShadow=4px&#038;offsetTopShadow=-4px&#038;offsetLeftShadow=-4px&#038;cornerRadiusShadow=0pxdow%3D0px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/overcast-thumb.PNG" width="194" height="178" /></a></td>
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Lucida+Grande%2C+Lucida+Sans%2C+Arial%2C+sans-serif&#038;fwDefault=normal&#038;fsDefault=1.1em&#038;cornerRadius=10px&#038;bgColorHeader=3a8104&#038;bgTextureHeader=03_highlight_soft.png&#038;bgImgOpacityHeader=33&#038;borderColorHeader=3f7506&#038;fcHeader=ffffff&#038;iconColorHeader=ffffff&#038;bgColorContent=285c00&#038;bgTextureContent=05_inset_soft.png&#038;bgImgOpacityContent=10&#038;borderColorContent=72b42d&#038;fcContent=ffffff&#038;iconColorContent=72b42d&#038;bgColorDefault=4ca20b&#038;bgTextureDefault=03_highlight_soft.png&#038;bgImgOpacityDefault=60&#038;borderColorDefault=45930b&#038;fcDefault=ffffff&#038;iconColorDefault=ffffff&#038;bgColorHover=4eb305&#038;bgTextureHover=03_highlight_soft.png&#038;bgImgOpacityHover=50&#038;borderColorHover=8bd83b&#038;fcHover=ffffff&#038;iconColorHover=ffffff&#038;bgColorActive=285c00&#038;bgTextureActive=04_highlight_hard.png&#038;bgImgOpacityActive=30&#038;borderColorActive=72b42d&#038;fcActive=ffffff&#038;iconColorActive=ffffff&#038;bgColorHighlight=fbf5d0&#038;bgTextureHighlight=02_glass.png&#038;bgImgOpacityHighlight=55&#038;borderColorHighlight=f9dd34&#038;fcHighlight=363636&#038;iconColorHighlight=4eb305&#038;bgColorError=ffdc2e&#038;bgTextureError=08_diagonals_thick.png&#038;bgImgOpacityError=95&#038;borderColorError=fad000&#038;fcError=2b2b2b&#038;iconColorError=cd0a0a&#038;bgColorOverlay=444444&#038;bgTextureOverlay=08_diagonals_thick.png&#038;bgImgOpacityOverlay=15&#038;opacityOverlay=30&#038;bgColorShadow=aaaaaa&#038;bgTextureShadow=07_diagonals_small.png&#038;bgImgOpacityShadow=0&#038;opacityShadow=30&#038;thicknessShadow=0px&#038;offsetTopShadow=4px&#038;offsetLeftShadow=4px&#038;cornerRadiusShadow=4px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/le-frog-thumb.PNG" width="194" height="169" /></a></td>
</tr>
<tr>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/overcast/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/le-frog/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
</tr>
<tr>
<td colspan="2">
<hr /></td>
</tr>
<tr>
<td align="center"><strong>Flick</strong></td>
<td align="center"><strong>Pepper Grinder</strong></td>
<tr valign="top">
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Helvetica%2C+Arial%2C+sans-serif&#038;fwDefault=bold&#038;fsDefault=1.1em&#038;cornerRadius=2px&#038;bgColorHeader=dddddd&#038;bgTextureHeader=03_highlight_soft.png&#038;bgImgOpacityHeader=50&#038;borderColorHeader=dddddd&#038;fcHeader=444444&#038;iconColorHeader=0073ea&#038;bgColorContent=ffffff&#038;bgTextureContent=01_flat.png&#038;bgImgOpacityContent=75&#038;borderColorContent=dddddd&#038;fcContent=444444&#038;iconColorContent=ff0084&#038;bgColorDefault=f6f6f6&#038;bgTextureDefault=03_highlight_soft.png&#038;bgImgOpacityDefault=100&#038;borderColorDefault=dddddd&#038;fcDefault=0073ea&#038;iconColorDefault=666666&#038;bgColorHover=0073ea&#038;bgTextureHover=03_highlight_soft.png&#038;bgImgOpacityHover=25&#038;borderColorHover=0073ea&#038;fcHover=ffffff&#038;iconColorHover=ffffff&#038;bgColorActive=ffffff&#038;bgTextureActive=02_glass.png&#038;bgImgOpacityActive=65&#038;borderColorActive=dddddd&#038;fcActive=ff0084&#038;iconColorActive=454545&#038;bgColorHighlight=ffffff&#038;bgTextureHighlight=01_flat.png&#038;bgImgOpacityHighlight=55&#038;borderColorHighlight=cccccc&#038;fcHighlight=444444&#038;iconColorHighlight=0073ea&#038;bgColorError=ffffff&#038;bgTextureError=01_flat.png&#038;bgImgOpacityError=55&#038;borderColorError=ff0084&#038;fcError=222222&#038;iconColorError=ff0084&#038;bgColorOverlay=eeeeee&#038;bgTextureOverlay=01_flat.png&#038;bgImgOpacityOverlay=0&#038;opacityOverlay=80&#038;bgColorShadow=aaaaaa&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=0&#038;opacityShadow=60&#038;thicknessShadow=4px&#038;offsetTopShadow=-4px&#038;offsetLeftShadow=-4px&#038;cornerRadiusShadow=0px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/flick-thumb.PNG" width="194" height="160" /></a></td>
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Trebuchet+MS%2C+Tahoma%2C+Verdana%2C+Arial%2C+sans-serif&#038;fwDefault=bold&#038;fsDefault=1.1em&#038;cornerRadius=6px&#038;bgColorHeader=ffffff&#038;bgTextureHeader=23_fine_grain.png&#038;bgImgOpacityHeader=15&#038;borderColorHeader=d4d1bf&#038;fcHeader=453821&#038;iconColorHeader=b83400&#038;bgColorContent=eceadf&#038;bgTextureContent=23_fine_grain.png&#038;bgImgOpacityContent=10&#038;borderColorContent=d9d6c4&#038;fcContent=1f1f1f&#038;iconColorContent=222222&#038;bgColorDefault=f8f7f6&#038;bgTextureDefault=23_fine_grain.png&#038;bgImgOpacityDefault=10&#038;borderColorDefault=cbc7bd&#038;fcDefault=654b24&#038;iconColorDefault=b83400&#038;bgColorHover=654b24&#038;bgTextureHover=23_fine_grain.png&#038;bgImgOpacityHover=65&#038;borderColorHover=654b24&#038;fcHover=ffffff&#038;iconColorHover=ffffff&#038;bgColorActive=eceadf&#038;bgTextureActive=23_fine_grain.png&#038;bgImgOpacityActive=15&#038;borderColorActive=d9d6c4&#038;fcActive=140f06&#038;iconColorActive=8c291d&#038;bgColorHighlight=f7f3de&#038;bgTextureHighlight=23_fine_grain.png&#038;bgImgOpacityHighlight=15&#038;borderColorHighlight=b2a266&#038;fcHighlight=3a3427&#038;iconColorHighlight=3572ac&#038;bgColorError=b83400&#038;bgTextureError=23_fine_grain.png&#038;bgImgOpacityError=68&#038;borderColorError=681818&#038;fcError=ffffff&#038;iconColorError=fbdb93&#038;bgColorOverlay=6e4f1c&#038;bgTextureOverlay=16_diagonal_maze.png&#038;bgImgOpacityOverlay=20&#038;opacityOverlay=60&#038;bgColorShadow=000000&#038;bgTextureShadow=16_diagonal_maze.png&#038;bgImgOpacityShadow=40&#038;opacityShadow=60&#038;thicknessShadow=5px&#038;offsetTopShadow=0&#038;offsetLeftShadow=-10px&#038;cornerRadiusShadow=18px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/pepper-grinder-thumb.PNG" width="194" height="178" /></a></td>
</tr>
<tr>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/flick/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/pepper-grinder/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
</tr>
<tr>
<td colspan="2">
<hr /></td>
</tr>
<tr>
<td align="center"><strong>Eggplant</strong></td>
<td align="center"><strong>Dark Hive</strong></td>
<tr valign="top">
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Lucida+Grande%2C+Lucida+Sans%2C+Arial%2C+sans-serif&#038;fwDefault=bold&#038;fsDefault=1.1em&#038;cornerRadius=6px&#038;bgColorHeader=30273a&#038;bgTextureHeader=03_highlight_soft.png&#038;bgImgOpacityHeader=25&#038;borderColorHeader=231d2b&#038;fcHeader=ffffff&#038;iconColorHeader=a8a3ae&#038;bgColorContent=3d3644&#038;bgTextureContent=12_gloss_wave.png&#038;bgImgOpacityContent=30&#038;borderColorContent=7e7783&#038;fcContent=ffffff&#038;iconColorContent=ffffff&#038;bgColorDefault=dcd9de&#038;bgTextureDefault=03_highlight_soft.png&#038;bgImgOpacityDefault=100&#038;borderColorDefault=dcd9de&#038;fcDefault=665874&#038;iconColorDefault=8d78a5&#038;bgColorHover=eae6ea&#038;bgTextureHover=03_highlight_soft.png&#038;bgImgOpacityHover=100&#038;borderColorHover=d1c5d8&#038;fcHover=734d99&#038;iconColorHover=734d99&#038;bgColorActive=5f5964&#038;bgTextureActive=03_highlight_soft.png&#038;bgImgOpacityActive=45&#038;borderColorActive=7e7783&#038;fcActive=ffffff&#038;iconColorActive=454545&#038;bgColorHighlight=fafafa&#038;bgTextureHighlight=01_flat.png&#038;bgImgOpacityHighlight=55&#038;borderColorHighlight=ffdb1f&#038;fcHighlight=333333&#038;iconColorHighlight=8d78a5&#038;bgColorError=994d53&#038;bgTextureError=01_flat.png&#038;bgImgOpacityError=55&#038;borderColorError=994d53&#038;fcError=ffffff&#038;iconColorError=ebccce&#038;bgColorOverlay=eeeeee&#038;bgTextureOverlay=01_flat.png&#038;bgImgOpacityOverlay=0&#038;opacityOverlay=80&#038;bgColorShadow=aaaaaa&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=0&#038;opacityShadow=60&#038;thicknessShadow=4px&#038;offsetTopShadow=-4px&#038;offsetLeftShadow=-4px&#038;cornerRadiusShadow=0px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/eggplant-thumb.PNG" width="194" height="154" /></a></td>
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Verdana%2C+Arial%2C+sans-serif&#038;fwDefault=normal&#038;fsDefault=1.1em&#038;cornerRadius=6px&#038;bgColorHeader=444444&#038;bgTextureHeader=03_highlight_soft.png&#038;bgImgOpacityHeader=44&#038;borderColorHeader=333333&#038;fcHeader=ffffff&#038;iconColorHeader=ffffff&#038;bgColorContent=000000&#038;bgTextureContent=14_loop.png&#038;bgImgOpacityContent=25&#038;borderColorContent=555555&#038;fcContent=ffffff&#038;iconColorContent=cccccc&#038;bgColorDefault=222222&#038;bgTextureDefault=03_highlight_soft.png&#038;bgImgOpacityDefault=35&#038;borderColorDefault=444444&#038;fcDefault=eeeeee&#038;iconColorDefault=cccccc&#038;bgColorHover=003147&#038;bgTextureHover=03_highlight_soft.png&#038;bgImgOpacityHover=33&#038;borderColorHover=0b93d5&#038;fcHover=ffffff&#038;iconColorHover=ffffff&#038;bgColorActive=0972a5&#038;bgTextureActive=04_highlight_hard.png&#038;bgImgOpacityActive=20&#038;borderColorActive=26b3f7&#038;fcActive=ffffff&#038;iconColorActive=222222&#038;bgColorHighlight=eeeeee&#038;bgTextureHighlight=03_highlight_soft.png&#038;bgImgOpacityHighlight=80&#038;borderColorHighlight=cccccc&#038;fcHighlight=2e7db2&#038;iconColorHighlight=4b8e0b&#038;bgColorError=ffc73d&#038;bgTextureError=02_glass.png&#038;bgImgOpacityError=40&#038;borderColorError=ffb73d&#038;fcError=111111&#038;iconColorError=a83300&#038;bgColorOverlay=5c5c5c&#038;bgTextureOverlay=01_flat.png&#038;bgImgOpacityOverlay=50&#038;opacityOverlay=80&#038;bgColorShadow=cccccc&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=30&#038;opacityShadow=60&#038;thicknessShadow=7px&#038;offsetTopShadow=-7px&#038;offsetLeftShadow=-7px&#038;cornerRadiusShadow=8px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/dark-hive-thumb.PNG" width="194" height="160" /></a></td>
</tr>
<tr>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/eggplant/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/dark-hive/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
</tr>
<tr>
<td colspan="2">
<hr /></td>
</tr>
<tr>
<td align="center"><strong>Cupertino</strong></td>
<td align="center"><strong>South Street</strong></td>
<tr valign="top">
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Lucida+Grande%2C+Lucida+Sans%2C+Arial%2C+sans-serif&#038;fwDefault=bold&#038;fsDefault=1.1em&#038;cornerRadius=6px&#038;bgColorHeader=deedf7&#038;bgTextureHeader=03_highlight_soft.png&#038;bgImgOpacityHeader=100&#038;borderColorHeader=aed0ea&#038;fcHeader=222222&#038;iconColorHeader=72a7cf&#038;bgColorContent=f2f5f7&#038;bgTextureContent=04_highlight_hard.png&#038;bgImgOpacityContent=100&#038;borderColorContent=dddddd&#038;fcContent=362b36&#038;iconColorContent=72a7cf&#038;bgColorDefault=d7ebf9&#038;bgTextureDefault=02_glass.png&#038;bgImgOpacityDefault=80&#038;borderColorDefault=aed0ea&#038;fcDefault=2779aa&#038;iconColorDefault=3d80b3&#038;bgColorHover=e4f1fb&#038;bgTextureHover=02_glass.png&#038;bgImgOpacityHover=100&#038;borderColorHover=74b2e2&#038;fcHover=0070a3&#038;iconColorHover=2694e8&#038;bgColorActive=3baae3&#038;bgTextureActive=02_glass.png&#038;bgImgOpacityActive=50&#038;borderColorActive=2694e8&#038;fcActive=ffffff&#038;iconColorActive=ffffff&#038;bgColorHighlight=ffef8f&#038;bgTextureHighlight=03_highlight_soft.png&#038;bgImgOpacityHighlight=25&#038;borderColorHighlight=f9dd34&#038;fcHighlight=363636&#038;iconColorHighlight=2e83ff&#038;bgColorError=cd0a0a&#038;bgTextureError=01_flat.png&#038;bgImgOpacityError=15&#038;borderColorError=cd0a0a&#038;fcError=ffffff&#038;iconColorError=ffffff&#038;bgColorOverlay=eeeeee&#038;bgTextureOverlay=08_diagonals_thick.png&#038;bgImgOpacityOverlay=90&#038;opacityOverlay=80&#038;bgColorShadow=000000&#038;bgTextureShadow=04_highlight_hard.png&#038;bgImgOpacityShadow=70&#038;opacityShadow=30&#038;thicknessShadow=7px&#038;offsetTopShadow=-7px&#038;offsetLeftShadow=-7px&#038;cornerRadiusShadow=8px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/cupertino-thumb.PNG" width="194" height="154" /></a></td>
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=segoe+ui%2C+Arial%2C+sans-serif&#038;fwDefault=bold&#038;fsDefault=1.1em&#038;cornerRadius=6px&#038;bgColorHeader=ece8da&#038;bgTextureHeader=12_gloss_wave.png&#038;bgImgOpacityHeader=100&#038;borderColorHeader=d4ccb0&#038;fcHeader=433f38&#038;iconColorHeader=847e71&#038;bgColorContent=f5f3e5&#038;bgTextureContent=04_highlight_hard.png&#038;bgImgOpacityContent=100&#038;borderColorContent=dfd9c3&#038;fcContent=312e25&#038;iconColorContent=808080&#038;bgColorDefault=459e00&#038;bgTextureDefault=04_highlight_hard.png&#038;bgImgOpacityDefault=15&#038;borderColorDefault=327E04&#038;fcDefault=ffffff&#038;iconColorDefault=eeeeee&#038;bgColorHover=67b021&#038;bgTextureHover=03_highlight_soft.png&#038;bgImgOpacityHover=25&#038;borderColorHover=327E04&#038;fcHover=ffffff&#038;iconColorHover=ffffff&#038;bgColorActive=fafaf4&#038;bgTextureActive=04_highlight_hard.png&#038;bgImgOpacityActive=100&#038;borderColorActive=d4ccb0&#038;fcActive=459e00&#038;iconColorActive=8DC262&#038;bgColorHighlight=fcf0ba&#038;bgTextureHighlight=02_glass.png&#038;bgImgOpacityHighlight=55&#038;borderColorHighlight=e8e1b5&#038;fcHighlight=363636&#038;iconColorHighlight=8DC262&#038;bgColorError=ffedad&#038;bgTextureError=03_highlight_soft.png&#038;bgImgOpacityError=95&#038;borderColorError=e3a345&#038;fcError=cd5c0a&#038;iconColorError=cd0a0a&#038;bgColorOverlay=2b2922&#038;bgTextureOverlay=05_inset_soft.png&#038;bgImgOpacityOverlay=15&#038;opacityOverlay=90&#038;bgColorShadow=cccccc&#038;bgTextureShadow=04_highlight_hard.png&#038;bgImgOpacityShadow=95&#038;opacityShadow=20&#038;thicknessShadow=12px&#038;offsetTopShadow=-12px&#038;offsetLeftShadow=-12px&#038;cornerRadiusShadow=10px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/south-street-thumb.PNG" width="194" height="160" /></a></td>
</tr>
<tr>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/cupertino/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/south-street/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
</tr>
<tr>
<td colspan="2">
<hr /></td>
</tr>
<tr>
<td align="center"><strong>Blitzer</strong></td>
<td align="center"><strong>Humanity</strong></td>
<tr valign="top">
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Arial,sans-serif&#038;fwDefault=bold&#038;fsDefault=1.1em&#038;cornerRadius=6px&#038;bgColorHeader=cc0000&#038;bgTextureHeader=03_highlight_soft.png&#038;bgImgOpacityHeader=15&#038;borderColorHeader=e3a1a1&#038;fcHeader=ffffff&#038;iconColorHeader=ffffff&#038;bgColorContent=ffffff&#038;bgTextureContent=01_flat.png&#038;bgImgOpacityContent=75&#038;borderColorContent=eeeeee&#038;fcContent=333333&#038;iconColorContent=cc0000&#038;bgColorDefault=eeeeee&#038;bgTextureDefault=04_highlight_hard.png&#038;bgImgOpacityDefault=100&#038;borderColorDefault=d8dcdf&#038;fcDefault=004276&#038;iconColorDefault=cc0000&#038;bgColorHover=f6f6f6&#038;bgTextureHover=04_highlight_hard.png&#038;bgImgOpacityHover=100&#038;borderColorHover=cdd5da&#038;fcHover=111111&#038;iconColorHover=cc0000&#038;bgColorActive=ffffff&#038;bgTextureActive=01_flat.png&#038;bgImgOpacityActive=65&#038;borderColorActive=eeeeee&#038;fcActive=cc0000&#038;iconColorActive=cc0000&#038;bgColorHighlight=fbf8ee&#038;bgTextureHighlight=02_glass.png&#038;bgImgOpacityHighlight=55&#038;borderColorHighlight=fcd3a1&#038;fcHighlight=444444&#038;iconColorHighlight=004276&#038;bgColorError=f3d8d8&#038;bgTextureError=08_diagonals_thick.png&#038;bgImgOpacityError=75&#038;borderColorError=cc0000&#038;fcError=2e2e2e&#038;iconColorError=cc0000&#038;bgColorOverlay=a6a6a6&#038;bgTextureOverlay=09_dots_small.png&#038;bgImgOpacityOverlay=65&#038;opacityOverlay=40&#038;bgColorShadow=333333&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=0&#038;opacityShadow=10&#038;thicknessShadow=8px&#038;offsetTopShadow=-8px&#038;offsetLeftShadow=-8px&#038;cornerRadiusShadow=8px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/blitzer-thumb.PNG" width="194" height="160" /></a></td>
<td align="center"><a href="http://jqueryui.com/themeroller/?tr=ffDefault=Helvetica,Arial,sans-serif&#038;fwDefault=normal&#038;fsDefault=1.1em&#038;cornerRadius=6px&#038;bgColorHeader=cb842e&#038;bgTextureHeader=02_glass.png&#038;bgImgOpacityHeader=25&#038;borderColorHeader=d49768&#038;fcHeader=ffffff&#038;iconColorHeader=ffffff&#038;bgColorContent=f4f0ec&#038;bgTextureContent=05_inset_soft.png&#038;bgImgOpacityContent=100&#038;borderColorContent=e0cfc2&#038;fcContent=1e1b1d&#038;iconColorContent=c47a23&#038;bgColorDefault=ede4d4&#038;bgTextureDefault=02_glass.png&#038;bgImgOpacityDefault=70&#038;borderColorDefault=cdc3b7&#038;fcDefault=3f3731&#038;iconColorDefault=f08000&#038;bgColorHover=f5f0e5&#038;bgTextureHover=02_glass.png&#038;bgImgOpacityHover=100&#038;borderColorHover=f5ad66&#038;fcHover=a46313&#038;iconColorHover=f08000&#038;bgColorActive=f4f0ec&#038;bgTextureActive=04_highlight_hard.png&#038;bgImgOpacityActive=100&#038;borderColorActive=e0cfc2&#038;fcActive=b85700&#038;iconColorActive=f35f07&#038;bgColorHighlight=f5f5b5&#038;bgTextureHighlight=04_highlight_hard.png&#038;bgImgOpacityHighlight=75&#038;borderColorHighlight=d9bb73&#038;fcHighlight=060200&#038;iconColorHighlight=cb672b&#038;bgColorError=fee4bd&#038;bgTextureError=04_highlight_hard.png&#038;bgImgOpacityError=65&#038;borderColorError=f8893f&#038;fcError=592003&#038;iconColorError=ff7519&#038;bgColorOverlay=aaaaaa&#038;bgTextureOverlay=01_flat.png&#038;bgImgOpacityOverlay=75&#038;opacityOverlay=30&#038;bgColorShadow=aaaaaa&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=75&#038;opacityShadow=30&#038;thicknessShadow=8px&#038;offsetTopShadow=-8px&#038;offsetLeftShadow=-8px&#038;cornerRadiusShadow=8px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/humanity-thumb.PNG" width="194" height="160" /></a></td>
</tr>
<tr>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/blitzer/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/humanity/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
</tr>
<tr>
<td colspan="2">
<hr /></td>
</tr>
<tr>
<td align="center"><strong>Hot Sneaks</strong></td>
<td align="center"><strong>Excite Bike</strong></td>
<tr valign="top">
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Gill+Sans,Arial,sans-serif&#038;fwDefault=bold&#038;fsDefault=1.2em&#038;cornerRadius=4px&#038;bgColorHeader=35414f&#038;bgTextureHeader=09_dots_small.png&#038;bgImgOpacityHeader=35&#038;borderColorHeader=2c4359&#038;fcHeader=e1e463&#038;iconColorHeader=e1e463&#038;bgColorContent=ffffff&#038;bgTextureContent=01_flat.png&#038;bgImgOpacityContent=75&#038;borderColorContent=aaaaaa&#038;fcContent=2c4359&#038;iconColorContent=c02669&#038;bgColorDefault=93c3cd&#038;bgTextureDefault=07_diagonals_small.png&#038;bgImgOpacityDefault=50&#038;borderColorDefault=93c3cd&#038;fcDefault=333333&#038;iconColorDefault=ffffff&#038;bgColorHover=ccd232&#038;bgTextureHover=07_diagonals_small.png&#038;bgImgOpacityHover=75&#038;borderColorHover=999999&#038;fcHover=212121&#038;iconColorHover=454545&#038;bgColorActive=db4865&#038;bgTextureActive=07_diagonals_small.png&#038;bgImgOpacityActive=40&#038;borderColorActive=ff6b7f&#038;fcActive=ffffff&#038;iconColorActive=ffffff&#038;bgColorHighlight=ffff38&#038;bgTextureHighlight=10_dots_medium.png&#038;bgImgOpacityHighlight=80&#038;borderColorHighlight=b4d100&#038;fcHighlight=363636&#038;iconColorHighlight=88a206&#038;bgColorError=ff3853&#038;bgTextureError=07_diagonals_small.png&#038;bgImgOpacityError=50&#038;borderColorError=ff6b7f&#038;fcError=ffffff&#038;iconColorError=ffeb33&#038;bgColorOverlay=f7f7ba&#038;bgTextureOverlay=11_white_lines.png&#038;bgImgOpacityOverlay=85&#038;opacityOverlay=80&#038;bgColorShadow=ba9217&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=75&#038;opacityShadow=20&#038;thicknessShadow=10px&#038;offsetTopShadow=8px&#038;offsetLeftShadow=8px&#038;cornerRadiusShadow=5px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/hot-sneaks-thumb.PNG" width="194" height="164" /></a></td>
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=segoe+ui,+Arial,+sans-serif&#038;fwDefault=bold&#038;fsDefault=1.1em&#038;cornerRadius=3px&#038;bgColorHeader=f9f9f9&#038;bgTextureHeader=03_highlight_soft.png&#038;bgImgOpacityHeader=100&#038;borderColorHeader=cccccc&#038;fcHeader=e69700&#038;iconColorHeader=5fa5e3&#038;bgColorContent=eeeeee&#038;bgTextureContent=06_inset_hard.png&#038;bgImgOpacityContent=100&#038;borderColorContent=aaaaaa&#038;fcContent=222222&#038;iconColorContent=0a82eb&#038;bgColorDefault=1484e6&#038;bgTextureDefault=08_diagonals_thick.png&#038;bgImgOpacityDefault=22&#038;borderColorDefault=ffffff&#038;fcDefault=ffffff&#038;iconColorDefault=fcdd4a&#038;bgColorHover=2293f7&#038;bgTextureHover=08_diagonals_thick.png&#038;bgImgOpacityHover=26&#038;borderColorHover=2293f7&#038;fcHover=ffffff&#038;iconColorHover=ffffff&#038;bgColorActive=e69700&#038;bgTextureActive=08_diagonals_thick.png&#038;bgImgOpacityActive=20&#038;borderColorActive=e69700&#038;fcActive=ffffff&#038;iconColorActive=ffffff&#038;bgColorHighlight=c5ddfc&#038;bgTextureHighlight=07_diagonals_small.png&#038;bgImgOpacityHighlight=25&#038;borderColorHighlight=ffffff&#038;fcHighlight=333333&#038;iconColorHighlight=0b54d5&#038;bgColorError=e69700&#038;bgTextureError=08_diagonals_thick.png&#038;bgImgOpacityError=20&#038;borderColorError=e69700&#038;fcError=ffffff&#038;iconColorError=ffffff&#038;bgColorOverlay=e6b900&#038;bgTextureOverlay=01_flat.png&#038;bgImgOpacityOverlay=0&#038;opacityOverlay=30&#038;bgColorShadow=e69700&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=0&#038;opacityShadow=20&#038;thicknessShadow=0px&#038;offsetTopShadow=6px&#038;offsetLeftShadow=6px&#038;cornerRadiusShadow=3px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/excite-bike-thumb.PNG" width="194" height="160" /></a></td>
</tr>
<tr>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/hot-sneaks/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/excite-bike/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
</tr>
<tr>
<td colspan="2">
<hr /></td>
</tr>
<tr>
<td align="center"><strong>Vader</strong></td>
<td align="center"><strong>Dot Luv</strong></td>
<tr valign="top">
<td align="center"><a href="http://jqueryui.com/themeroller/?tr&#038;ffDefault=Helvetica,+Arial,+sans-serif&#038;fwDefault=normal&#038;fsDefault=1.1&#038;fsDefaultUnit=em&#038;cornerRadius=5&#038;cornerRadiusUnit=px&#038;bgColorHeader=888888&#038;bgTextureHeader=04_highlight_hard.png&#038;bgImgOpacityHeader=15&#038;borderColorHeader=404040&#038;fcHeader=ffffff&#038;iconColorHeader=cccccc&#038;bgColorContent=121212&#038;bgTextureContent=12_gloss_wave.png&#038;bgImgOpacityContent=16&#038;borderColorContent=404040&#038;fcContent=eeeeee&#038;iconColorContent=bbbbbb&#038;bgColorDefault=adadad&#038;bgTextureDefault=03_highlight_soft.png&#038;bgImgOpacityDefault=35&#038;borderColorDefault=cccccc&#038;fcDefault=333333&#038;iconColorDefault=666666&#038;bgColorHover=dddddd&#038;bgTextureHover=03_highlight_soft.png&#038;bgImgOpacityHover=60&#038;borderColorHover=dddddd&#038;fcHover=000000&#038;iconColorHover=c98000&#038;bgColorActive=121212&#038;bgTextureActive=05_inset_soft.png&#038;bgImgOpacityActive=15&#038;borderColorActive=000000&#038;fcActive=ffffff&#038;iconColorActive=f29a00&#038;bgColorHighlight=555555&#038;bgTextureHighlight=04_highlight_hard.png&#038;bgImgOpacityHighlight=55&#038;borderColorHighlight=404040&#038;fcHighlight=cccccc&#038;iconColorHighlight=aaaaaa&#038;bgColorError=fef1ec&#038;bgTextureError=02_glass.png&#038;bgImgOpacityError=95&#038;borderColorError=cd0a0a&#038;fcError=cd0a0a&#038;iconColorError=cd0a0a" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/vader-thumb.PNG" width="194" height="165" /></a></td>
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Arial,+sans-serif&#038;fwDefault=bold&#038;fsDefault=1.3em&#038;cornerRadius=4px&#038;bgColorHeader=0b3e6f&#038;bgTextureHeader=08_diagonals_thick.png&#038;bgImgOpacityHeader=15&#038;borderColorHeader=0b3e6f&#038;fcHeader=f6f6f6&#038;iconColorHeader=98d2fb&#038;bgColorContent=111111&#038;bgTextureContent=12_gloss_wave.png&#038;bgImgOpacityContent=20&#038;borderColorContent=000000&#038;fcContent=d9d9d9&#038;iconColorContent=9ccdfc&#038;bgColorDefault=333333&#038;bgTextureDefault=09_dots_small.png&#038;bgImgOpacityDefault=20&#038;borderColorDefault=333333&#038;fcDefault=ffffff&#038;iconColorDefault=9ccdfc&#038;bgColorHover=00498f&#038;bgTextureHover=09_dots_small.png&#038;bgImgOpacityHover=40&#038;borderColorHover=222222&#038;fcHover=ffffff&#038;iconColorHover=ffffff&#038;bgColorActive=292929&#038;bgTextureActive=01_flat.png&#038;bgImgOpacityActive=40&#038;borderColorActive=096ac8&#038;fcActive=75abff&#038;iconColorActive=00498f&#038;bgColorHighlight=0b58a2&#038;bgTextureHighlight=10_dots_medium.png&#038;bgImgOpacityHighlight=30&#038;borderColorHighlight=052f57&#038;fcHighlight=ffffff&#038;iconColorHighlight=ffffff&#038;bgColorError=a32d00&#038;bgTextureError=09_dots_small.png&#038;bgImgOpacityError=30&#038;borderColorError=cd0a0a&#038;fcError=ffffff&#038;iconColorError=ffffff&#038;bgColorOverlay=aaaaaa&#038;bgTextureOverlay=01_flat.png&#038;bgImgOpacityOverlay=0&#038;opacityOverlay=30&#038;bgColorShadow=aaaaaa&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=0&#038;opacityShadow=30&#038;thicknessShadow=8px&#038;offsetTopShadow=-8px&#038;offsetLeftShadow=-8px&#038;cornerRadiusShadow=8px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/dot-luv-thumb.PNG" width="194" height="162" /></a></td>
</tr>
<tr>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/vader/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/dot-luv-grinder/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
</tr>
<tr>
<td colspan="2">
<hr /></td>
</tr>
<tr>
<td align="center"><strong>Mint Choc</strong></td>
<td align="center"><strong>Black Tie</strong></td>
<tr valign="top">
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Segoe+UI%2C+Helvetica%2C+Arial%2C+sans-serif&#038;fwDefault=bold&#038;fsDefault=1.1em&#038;cornerRadius=4px&#038;bgColorHeader=453326&#038;bgTextureHeader=12_gloss_wave.png&#038;bgImgOpacityHeader=25&#038;borderColorHeader=695649&#038;fcHeader=e3ddc9&#038;iconColorHeader=e3ddc9&#038;bgColorContent=201913&#038;bgTextureContent=05_inset_soft.png&#038;bgImgOpacityContent=10&#038;borderColorContent=9c947c&#038;fcContent=ffffff&#038;iconColorContent=222222&#038;bgColorDefault=1c160d&#038;bgTextureDefault=12_gloss_wave.png&#038;bgImgOpacityDefault=20&#038;borderColorDefault=695444&#038;fcDefault=9bcc60&#038;iconColorDefault=9bcc60&#038;bgColorHover=44372c&#038;bgTextureHover=12_gloss_wave.png&#038;bgImgOpacityHover=30&#038;borderColorHover=9c947c&#038;fcHover=baec7e&#038;iconColorHover=add978&#038;bgColorActive=201913&#038;bgTextureActive=03_highlight_soft.png&#038;bgImgOpacityActive=20&#038;borderColorActive=9c947c&#038;fcActive=e3ddc9&#038;iconColorActive=e3ddc9&#038;bgColorHighlight=619226&#038;bgTextureHighlight=03_highlight_soft.png&#038;bgImgOpacityHighlight=20&#038;borderColorHighlight=add978&#038;fcHighlight=ffffff&#038;iconColorHighlight=ffffff&#038;bgColorError=5f391b&#038;bgTextureError=02_glass.png&#038;bgImgOpacityError=15&#038;borderColorError=5f391b&#038;fcError=ffffff&#038;iconColorError=f1fd86&#038;bgColorOverlay=aaaaaa&#038;bgTextureOverlay=01_flat.png&#038;bgImgOpacityOverlay=0&#038;opacityOverlay=30&#038;bgColorShadow=aaaaaa&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=0&#038;opacityShadow=30&#038;thicknessShadow=8px&#038;offsetTopShadow=-8px&#038;offsetLeftShadow=-8px&#038;cornerRadiusShadow=8px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/mint-choc-thumb.PNG" width="194" height="160" /></a></td>
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Verdana,+Arial,+sans-serif&#038;fwDefault=normal&#038;fsDefault=1.1em&#038;cornerRadius=4px&#038;bgColorHeader=333333&#038;bgTextureHeader=08_diagonals_thick.png&#038;bgImgOpacityHeader=8&#038;borderColorHeader=a3a3a3&#038;fcHeader=eeeeee&#038;iconColorHeader=bbbbbb&#038;bgColorContent=f9f9f9&#038;bgTextureContent=04_highlight_hard.png&#038;bgImgOpacityContent=100&#038;borderColorContent=cccccc&#038;fcContent=222222&#038;iconColorContent=222222&#038;bgColorDefault=111111&#038;bgTextureDefault=02_glass.png&#038;bgImgOpacityDefault=40&#038;borderColorDefault=777777&#038;fcDefault=e3e3e3&#038;iconColorDefault=ededed&#038;bgColorHover=1c1c1c&#038;bgTextureHover=02_glass.png&#038;bgImgOpacityHover=55&#038;borderColorHover=000000&#038;fcHover=ffffff&#038;iconColorHover=ffffff&#038;bgColorActive=ffffff&#038;bgTextureActive=01_flat.png&#038;bgImgOpacityActive=65&#038;borderColorActive=cccccc&#038;fcActive=222222&#038;iconColorActive=222222&#038;bgColorHighlight=ffeb80&#038;bgTextureHighlight=06_inset_hard.png&#038;bgImgOpacityHighlight=55&#038;borderColorHighlight=ffde2e&#038;fcHighlight=363636&#038;iconColorHighlight=4ca300&#038;bgColorError=cd0a0a&#038;bgTextureError=06_inset_hard.png&#038;bgImgOpacityError=45&#038;borderColorError=9e0505&#038;fcError=ffffff&#038;iconColorError=ffcf29&#038;bgColorOverlay=aaaaaa&#038;bgTextureOverlay=04_highlight_hard.png&#038;bgImgOpacityOverlay=40&#038;opacityOverlay=30&#038;bgColorShadow=aaaaaa&#038;bgTextureShadow=03_highlight_soft.png&#038;bgImgOpacityShadow=50&#038;opacityShadow=20&#038;thicknessShadow=8px&#038;offsetTopShadow=-8px&#038;offsetLeftShadow=-8px&#038;cornerRadiusShadow=8px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/black-tie-thumb.PNG" width="194" height="160" /></a></td>
</tr>
<tr>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/mint-choc/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/black-tie/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
</tr>
<tr>
<td colspan="2">
<hr /></td>
</tr>
<tr>
<td align="center"><strong>Trontastic</strong></td>
<td align="center"><strong>Swanky Purse</strong></td>
<tr valign="top">
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Segoe+UI,+Helvetica,+Arial,+sans-serif&#038;fwDefault=bold&#038;fsDefault=1.1em&#038;cornerRadius=6px&#038;bgColorHeader=9fda58&#038;bgTextureHeader=12_gloss_wave.png&#038;bgImgOpacityHeader=85&#038;borderColorHeader=000000&#038;fcHeader=222222&#038;iconColorHeader=1f1f1f&#038;bgColorContent=000000&#038;bgTextureContent=12_gloss_wave.png&#038;bgImgOpacityContent=55&#038;borderColorContent=4a4a4a&#038;fcContent=ffffff&#038;iconColorContent=9fda58&#038;bgColorDefault=0a0a0a&#038;bgTextureDefault=02_glass.png&#038;bgImgOpacityDefault=40&#038;borderColorDefault=1b1613&#038;fcDefault=b8ec79&#038;iconColorDefault=b8ec79&#038;bgColorHover=000000&#038;bgTextureHover=02_glass.png&#038;bgImgOpacityHover=60&#038;borderColorHover=000000&#038;fcHover=96f226&#038;iconColorHover=b8ec79&#038;bgColorActive=4c4c4c&#038;bgTextureActive=01_flat.png&#038;bgImgOpacityActive=0&#038;borderColorActive=696969&#038;fcActive=ffffff&#038;iconColorActive=ffffff&#038;bgColorHighlight=f1fbe5&#038;bgTextureHighlight=02_glass.png&#038;bgImgOpacityHighlight=55&#038;borderColorHighlight=8cce3b&#038;fcHighlight=030303&#038;iconColorHighlight=000000&#038;bgColorError=f6ecd5&#038;bgTextureError=12_gloss_wave.png&#038;bgImgOpacityError=95&#038;borderColorError=f1ac88&#038;fcError=74736d&#038;iconColorError=cd0a0a&#038;bgColorOverlay=262626&#038;bgTextureOverlay=07_diagonals_small.png&#038;bgImgOpacityOverlay=50&#038;opacityOverlay=30&#038;bgColorShadow=303030&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=0&#038;opacityShadow=50&#038;thicknessShadow=6px&#038;offsetTopShadow=-6px&#038;offsetLeftShadow=-6px&#038;cornerRadiusShadow=12px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/trontastic-thumb.PNG" width="194" height="160" /></a></td>
<td align="center"><a href="http://jqueryui.com/themeroller/?ffDefault=Georgia%2C+Verdana%2CArial%2Csans-serif&#038;fwDefault=bold&#038;fsDefault=1.2em&#038;cornerRadius=5px&#038;bgColorHeader=261803&#038;bgTextureHeader=13_diamond.png&#038;bgImgOpacityHeader=8&#038;borderColorHeader=baaa5a&#038;fcHeader=eacd86&#038;iconColorHeader=e9cd86&#038;bgColorContent=443113&#038;bgTextureContent=13_diamond.png&#038;bgImgOpacityContent=8&#038;borderColorContent=efec9f&#038;fcContent=efec9f&#038;iconColorContent=efec9f&#038;bgColorDefault=4f4221&#038;bgTextureDefault=13_diamond.png&#038;bgImgOpacityDefault=10&#038;borderColorDefault=362917&#038;fcDefault=f8eec9&#038;iconColorDefault=e8e2b5&#038;bgColorHover=675423&#038;bgTextureHover=13_diamond.png&#038;bgImgOpacityHover=25&#038;borderColorHover=362917&#038;fcHover=f8eec9&#038;iconColorHover=f2ec64&#038;bgColorActive=443113&#038;bgTextureActive=13_diamond.png&#038;bgImgOpacityActive=8&#038;borderColorActive=efec9f&#038;fcActive=f9f2bd&#038;iconColorActive=f9f2bd&#038;bgColorHighlight=d5ac5d&#038;bgTextureHighlight=13_diamond.png&#038;bgImgOpacityHighlight=25&#038;borderColorHighlight=362917&#038;fcHighlight=060200&#038;iconColorHighlight=070603&#038;bgColorError=fee4bd&#038;bgTextureError=04_highlight_hard.png&#038;bgImgOpacityError=65&#038;borderColorError=c26629&#038;fcError=803f1e&#038;iconColorError=ff7519&#038;bgColorOverlay=372806&#038;bgTextureOverlay=13_diamond.png&#038;bgImgOpacityOverlay=20&#038;opacityOverlay=80&#038;bgColorShadow=ddd4b0&#038;bgTextureShadow=01_flat.png&#038;bgImgOpacityShadow=75&#038;opacityShadow=30&#038;thicknessShadow=8px&#038;offsetTopShadow=-8px&#038;offsetLeftShadow=-8px&#038;cornerRadiusShadow=12px" target="_blank"><img src="http://encosia.com/blog/wp-content/uploads/2009/10/swanky-purse-thumb.PNG" width="194" height="164" /></a></td>
</tr>
<tr>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/trontastic/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
<td align="center" height="40" valign="middle">
<input type="text" value="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/swanky-purse/jquery-ui.css" onfocus="this.select();" style="width: 189px;" /></td>
</tr>
</table>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/10/11/do-you-know-about-this-undocumented-google-cdn-feature/">Do you know about this undocumented Google CDN feature?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2009/10/11/do-you-know-about-this-undocumented-google-cdn-feature/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		</item>
		<item>
		<title>Updated: See how I used Firebug to learn jQuery</title>
		<link>http://encosia.com/2009/09/21/updated-see-how-i-used-firebug-to-learn-jquery/</link>
		<comments>http://encosia.com/2009/09/21/updated-see-how-i-used-firebug-to-learn-jquery/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 05:44:41 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/?p=908</guid>
		<description><![CDATA[It was great to see all the positive responses to the screencast I recently recorded with Craig Shoemaker on how to use Firebug’s console to learn jQuery. That being my first screencast, I really appreciate all of your support.
However, you almost unanimously commented that it was too difficult to read the commands typed at the [...]<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/09/21/updated-see-how-i-used-firebug-to-learn-jquery/">Updated: See how I used Firebug to learn jQuery</a></p>
]]></description>
			<content:encoded><![CDATA[<p>It was great to see all the positive responses to the screencast I recently recorded with Craig Shoemaker on how to use Firebug’s console to learn jQuery. That being my first screencast, I really appreciate all of your support.</p>
<p>However, you almost unanimously commented that it was too difficult to read the commands typed at the console, and you were right. So, Craig and I re-recorded the entire thing, paying extra attention to the legibility of the end result.</p>
<p>Craig also managed to edit the same content down to 9:59m this time, so you can watch it on YouTube if you prefer:</p>
<p><object width="492" height="389"><param name="movie" value="http://www.youtube.com/v/JB6MIV_lHI0&#038;hl=en&#038;fs=1&#038;rel=0&#038;ap=%2526fmt%3D18"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/JB6MIV_lHI0&#038;hl=en&#038;fs=1&#038;rel=0&#038;ap=%2526fmt%3D18" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="492" height="389"></embed></object></p>
<p>If the HQ version of the YouTube video still isn’t legible enough for you, <a href="http://weblogs.asp.net/craigshoemaker/archive/2009/09/18/updated-video-for-using-firebug-and-jquery-post.aspx" target="_blank">Craig also made a full resolution WMV available as well</a>.</p>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/09/21/updated-see-how-i-used-firebug-to-learn-jquery/">Updated: See how I used Firebug to learn jQuery</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2009/09/21/updated-see-how-i-used-firebug-to-learn-jquery/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>See how I used Firebug to learn jQuery</title>
		<link>http://encosia.com/2009/08/10/see-how-i-used-firebug-to-learn-jquery/</link>
		<comments>http://encosia.com/2009/08/10/see-how-i-used-firebug-to-learn-jquery/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 15:42:59 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/2009/08/10/see-how-i-used-firebug-to-learn-jquery/</guid>
		<description><![CDATA[UPDATE: We&#8217;ve recorded a higher quality version of this screencast.
When I hear that someone’s having trouble learning JavaScript or jQuery, my first suggestion to them is always the same: install Firebug and experiment at the console. Whether you’re an experienced JavaScript developer or haven’t written a single line of client-side code, the interactive nature of [...]<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/08/10/see-how-i-used-firebug-to-learn-jquery/">See how I used Firebug to learn jQuery</a></p>
]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE:</strong> <a href="http://encosia.com/2009/09/21/updated-see-how-i-used-firebug-to-learn-jquery/">We&#8217;ve recorded a higher quality version of this screencast</a>.</p>
<p>When I hear that someone’s having trouble learning JavaScript or jQuery, my first suggestion to them is always the same: <strong>install Firebug and experiment at the console</strong>. Whether you’re an experienced JavaScript developer or haven’t written a single line of client-side code, <a href="http://www.codinghorror.com/blog/archives/001216.html" target="_blank">the interactive nature of a command-line is one of the fastest ways to learn</a>.</p>
<p>To demonstrate just how effective Firebug’s console can be, <a href="http://weblogs.asp.net/craigshoemaker/archive/2009/08/04/using-firebug-and-jquery.aspx" target="_blank">Craig Shoemaker</a> and I recorded a short screencast on the topic. If you’re not taking advantage of this technique, be sure to take a minute (well, 16) and check it out:</p>
<p><strike><a title="http://polymorphicpodcast.com/podcast/video/firebug-and-jquery/" href="http://polymorphicpodcast.com/podcast/video/firebug-and-jquery/">http://polymorphicpodcast.com/podcast/video/firebug-and-jquery/</a></strike></p>
<p><a href="http://encosia.com/2009/09/21/updated-see-how-i-used-firebug-to-learn-jquery/">http://encosia.com/2009/09/21/updated-see-how-i-used-firebug-to-learn-jquery/</a></p>
<p>Question: Would you like to see more screencasts similar to this one?</p>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/08/10/see-how-i-used-firebug-to-learn-jquery/">See how I used Firebug to learn jQuery</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2009/08/10/see-how-i-used-firebug-to-learn-jquery/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Simplify calling ASP.NET AJAX services from jQuery</title>
		<link>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/</link>
		<comments>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 17:11:37 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/?p=888</guid>
		<description><![CDATA[As jQuery’s popularity in the .NET community has risen over the past year, one recurring theme I’ve seen is the desire to refactor away the details of using it to call ASP.NET AJAX services. Whether through helper function or specialized jQuery plugin, I’ve seen numerous methods proposed and/or in use.
Personally, the syntax never bothered me. [...]<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/">Simplify calling ASP.NET AJAX services from jQuery</a></p>
]]></description>
			<content:encoded><![CDATA[<p>As jQuery’s popularity in the .NET community has risen over the past year, one recurring theme I’ve seen is the desire to refactor away the details of using it to call ASP.NET AJAX services. Whether through helper function or specialized jQuery plugin, I’ve seen numerous methods proposed and/or in use.</p>
<p>Personally, the syntax never bothered me. The contentType parameter is ugly, but I have a Visual Studio code snippet for the $.ajax call and rarely think about it.</p>
<p>That came to an end earlier this year, when I started using dataFilter. I needed to <a href="http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/" target="_blank">isolate my code from the “.d” issue</a>, and wanted to <a href="http://encosia.com/2009/07/07/improving-jquery-json-performance-and-security/" target="_blank">take advantage of browser-native JSON parsing</a> in Firefox 3.5 and IE8, which required a bulky dataFilter.</p>
<p>Repeating that entire callback function in every $.ajax call was not acceptable. So, I was happy to learn that jQuery provides an excellent solution for consolidating settings to be used in multiple instances of $.ajax.</p>
<p>In this post, I’ll show you <strong>how to use that consolidation feature</strong>, and exactly how I am now using that to <strong>more simply call ASP.NET AJAX services with jQuery</strong>.</p>
<h3>Configuring $.ajax’s default settings</h3>
<p>Rather than wrapping the $.ajax call in a plugin or helper function, jQuery provides a built-in solution that I think is a better alternative:&#160; <a href="http://docs.jquery.com/Ajax/jQuery.ajaxSetup" target="_blank">$.ajaxSetup</a>.</p>
<p>$.ajaxSetup accepts an array of settings that allows you to supply defaults for any of the parameters that you would set in an $.ajax call. Settings like <strong>contentType</strong>, <strong>type</strong>, and <strong>dataFilter</strong> are all fair game, for example.</p>
<p>Using this function, it’s easy to set jQuery’s $.ajax defaults to match <a href="http://encosia.com/2008/06/05/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/" target="_blank">the refined settings that we worked out together last year</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajaxSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
  contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json; charset=utf-8&quot;</span><span style="color: #339933;">,</span>
  data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;{}&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Because <strong>parameters to</strong> <strong>$.ajax override these defaults</strong>, presetting “data” to an empty JSON string is safe. Any $.ajax call that does specify a data parameter will function as expected, since the default will be ignored.</p>
<p>The particular issue caused by forgetting the empty data parameter can be difficult to track down, and only shows up after you’ve deployed your application to IIS. So, having the default as a safety net is recommended.</p>
<h3>Adding JSON parsing improvements</h3>
<p>Because $.ajaxSetup also supports setting a dataFilter, adding <a href="http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/" target="_blank">the “.d” isolation</a> and <a href="http://encosia.com/2009/07/07/improving-jquery-json-performance-and-security/" target="_blank">browser-native JSON parsing</a> from my last two posts is easy:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajaxSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
  contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json; charset=utf-8&quot;</span><span style="color: #339933;">,</span>
  data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;{}&quot;</span><span style="color: #339933;">,</span>
  dataFilter<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> msg<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #009900;">&#40;</span>JSON<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #3366CC;">'undefined'</span> <span style="color: #339933;">&amp;&amp;</span> 
        <span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #009900;">&#40;</span>JSON.<span style="color: #660066;">parse</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'function'</span><span style="color: #009900;">&#41;</span>
      msg <span style="color: #339933;">=</span> JSON.<span style="color: #660066;">parse</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
      msg <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'('</span> <span style="color: #339933;">+</span> data <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>msg.<span style="color: #660066;">hasOwnProperty</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'d'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #000066; font-weight: bold;">return</span> msg.<span style="color: #660066;">d</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
      <span style="color: #000066; font-weight: bold;">return</span> msg<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This dataFilter processing is actually what pushed me to start using $.ajaxSetup in all of my own projects. It was one thing to accept multiple contentType and method declarations, but repeating the dataFilter for every $.ajax call was more than I could handle.</p>
<h3>Putting it to work</h3>
<p>With the ASP.NET AJAX defaults set in $.ajaxSetup, <strong>all that’s required to call a “ScriptService” or page method is the URL and a success callback</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;HelloWorld.asmx/Hello&quot;</span><span style="color: #339933;">,</span>
  success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In fact, even the success callback is optional. For example, if you were periodically pinging a “heartbeat” service to keep the user’s session alive, $.ajax would only need the service&#8217;s URI.</p>
<p>This more concise syntax makes your service calls <em>far</em> more readable, especially for developers who aren’t familiar with the content-type required by ASP.NET AJAX. </p>
<h3>Caution: Sometimes it works too well</h3>
<p>While this is a handy way to simplify calls to ASP.NET AJAX services, do understand that <strong>$.ajaxSetup applies to all of jQuery’s AJAX derivatives</strong>. Setting the default HTTP method and content-type may also impact code and plugins that use jQuery’s built-in communication functionality (e.g. $.getJSON, $.post, etc).</p>
<p>For example, I often <a href="http://encosia.com/2008/06/26/use-jquery-and-aspnet-ajax-to-build-a-client-side-repeater/" target="_blank">use jTemplates as a client-side templating solution</a>. Because its processTemplateURL routine relies on $.ajax to retrieve remote template files, setting the ASP.NET AJAX content-type and POST method in $.ajaxSetup breaks that functionality of jTemplates.</p>
<p>Fixing that problem wasn’t difficult, but it also wasn’t immediately obvious what had caused the issue in the first place. In my experience using this technique, the undesirable side effects are rare enough that it’s not a serious concern, but do be aware of the potential.</p>
<h3>Conclusion</h3>
<p>I’ve been using this in production for several months now, with great results. Users have noticed the increased speed that came with browser-native JSON parsing, the “.d” isolation has reduced regression errors due to some code we run on both 2.0 and 3.5 servers, and <strong>it requires less effort on my part to do all that</strong>.</p>
<p>What do you think? Is this helpful?</p>
<p>Would a Visual Studio template with this rolled in be something you would use?</p>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/">Simplify calling ASP.NET AJAX services from jQuery</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/feed/</wfw:commentRss>
		<slash:comments>58</slash:comments>
		</item>
		<item>
		<title>Improving jQuery’s JSON performance and security</title>
		<link>http://encosia.com/2009/07/07/improving-jquery-json-performance-and-security/</link>
		<comments>http://encosia.com/2009/07/07/improving-jquery-json-performance-and-security/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 13:00:02 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/?p=886</guid>
		<description><![CDATA[When you’re working with JSON, performance and security are often opposing, yet equally important concerns. One of these areas of contention is handling the JSON strings returned by a server. Most JavaScript libraries do a great job of abstracting away the details, but the underlying process has long been a frustrating exercise in compromise.
On one [...]<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/07/07/improving-jquery-json-performance-and-security/">Improving jQuery’s JSON performance and security</a></p>
]]></description>
			<content:encoded><![CDATA[<p>When you’re working with JSON, <strong>performance</strong> and <strong>security</strong> are often opposing, yet equally important concerns. One of these areas of contention is handling the JSON strings returned by a server. Most JavaScript libraries do a great job of abstracting away the details, but the underlying process has long been a frustrating exercise in compromise.</p>
<p>On one hand, eval() is the fastest widely available method, <a href="http://yuiblog.com/blog/2007/04/10/json-and-browser-security/" target="_blank">but it is not safe</a>.</p>
<p>On the other hand, textual JSON parsers written in JavaScript may be much safer, but are <strong>dramatically slower</strong>. In client-side situations, <a href="http://encosia.com/2009/06/09/11-keystrokes-that-made-my-jquery-selector-run-10x-faster/" target="_blank">where milliseconds count</a>, such a large performance overhead is typically too prohibitive to accept.</p>
<p>Recently, an exciting new alternative has emerged: <strong>browser-native JSON parsing</strong>. Integrating JSON parsing as part of the browser’s implementation of JavaScript allows for using the more secure parsing method, <em>and</em> even provides performance faster than eval() offers.</p>
<p>To take advantage of that, this post will show you how to <strong>detect whether or not a browser supports native JSON parsing</strong>, and how to <strong>force jQuery to use browser-native parsing</strong> in its $.ajax calls when it is available.</p>
<h3>Native JSON parsing in the browser</h3>
<p>Previously known as ECMAScript 3.1, ECMAScript “Fifth Edition” (the specification that JavaScript implements) formally codifies a native JSON parsing feature. The spec’s API exactly mirrors that of <a href="http://www.json.org/js.html" target="_blank">Crockford’s implementations of JSON.parse and JSON.stringify in json2.js</a>, easing the transition to browser-native functionality.</p>
<p>This native JSON parsing brings marked improvements in terms of <strong>both security and performance</strong>. Not only does the native routine use textual parsing to avoid the risk of executing malicious code embedded within JSON, but it is also <em>fast.</em></p>
<p>At the time of this writing, three major browsers <em>already</em> include support for native JSON parsing: <strong>IE8</strong>, <strong>Firefox 3.5</strong>, and <strong>Chrome 3</strong>.</p>
<p>Safari 4 does not currently support the standard, but its underlying engine (WebKit) <a href="https://bugs.webkit.org/show_bug.cgi?id=20031" rel="nofollow" target="_blank">has recently implemented it</a>. Hopefully the feature will make its way to Safari soon.</p>
<h3>Detecting native JSON support</h3>
<p>Determining whether or not native JSON parsing is available within a given browser is the first problem we need to solve. To do this, we ultimately need to know if the <strong>JSON.parse</strong> function is defined.</p>
<p>We can’t test for JSON.parse directly because attempting to reference it will throw a JavaScript error if the underlying JSON object doesn’t exist. So, first we need to inspect the type of that underlying object itself:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>JSON<span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'object'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  <span style="color: #006600; font-style: italic;">// native JSON may be available.</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If we find that the JSON object does exist, it’s likely that native JSON parsing is available. However, it’s a best to double check the JSON.parse function as well:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>JSON.<span style="color: #660066;">parse</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'function'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// native JSON parsing is available.</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Because JavaScript performs <a href="http://en.wikipedia.org/wiki/Short-circuit_evaluation" rel="nofollow" target="_blank">short-circuit evaluation</a>, it’s safe to clean this up by combining both tests in a single conditional, as long as they&#8217;re in this order:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>JSON<span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'object'</span> <span style="color: #339933;">&amp;&amp;</span> 
    <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>JSON.<span style="color: #660066;">parse</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'function'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Native JSON parsing is available.</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Curious whether your browser supports native JSON parsing? Using the JavaScript above, I have determined that: <strong><script type="text/javascript">if (typeof(JSON) === 'object') { if (typeof(JSON.parse) === 'function') { document.write('It does!'); } } else { document.write('It does not.'); }</script></strong></p>
<p><noscript>You appear to have JavaScript disabled or are reading this in an RSS reader.  In order to view the status of your browser&#8217;s native JSON capability, <a target="_blank" href="http://encosia.com/2009/07/07/improving-jquery-json-performance-and-security/">please view this post in a browser with JavaScript enabled</a>.</noscript></p>
<h3>Extending jQuery to use native JSON parsing</h3>
<p>In my previous post, I demonstrated how to <a href="http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/" target="_blank">use jQuery’s dataFilter to transform a JSON response</a> before it is returned to the $.ajax() success handler. In the process, we also preempted jQuery’s default method for deserializing JSON data.</p>
<p>The focus at that time was implementing the same method for JSON parsing that jQuery uses by default, so eval() was still used. However, we can also use the same dataFilter mechanism to force browser-native JSON parsing instead.</p>
<p>Using our JSON parsing detection code and a dataFilter callback, upgrading jQuery to use browser-native parsing is simple:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Your usual $.ajax() URL, data, dataType, etc.</span>
  dataFilter<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #009900;">&#40;</span>JSON<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #3366CC;">'undefined'</span> <span style="color: #339933;">&amp;&amp;</span> 
        <span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #009900;">&#40;</span>JSON.<span style="color: #660066;">parse</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">'function'</span><span style="color: #009900;">&#41;</span>
      <span style="color: #000066; font-weight: bold;">return</span> JSON.<span style="color: #660066;">parse</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
      <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'('</span> <span style="color: #339933;">+</span> data <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Because jQuery only attempts to deserialize JSON responses if their type is string, and because the dataFilter callback executes <em>before</em> jQuery would normally perform that deserialization, this technique preempts jQuery’s JSON evaluation completely. In the worst case, it will simply revert back to the same eval() method that jQuery internally uses by default anyway.</p>
<p><em>Note: It’s important to keep in mind that the dataFilter will run regardless of what type is actually returned from the server. You should only use this when you’re sure that you’re receiving a JSON string.</em></p>
<h3>Conclusion</h3>
<p>If you’ve been paying close attention to jQuery’s ongoing development, you may already know that <a href="http://dev.jquery.com/ticket/4429" rel="nofollow" target="_blank">jQuery 1.3.3 will provide functionality very similar to what I’ve shown you</a>. I decided to go ahead and write this post anyway for a few reasons:</p>
<ul>
<li>You can use this <strong>today</strong>, without waiting for jQuery 1.3.3.</li>
<li>You can use this in previous versions of jQuery, if upgrading isn’t feasible for you (as is often the case with plugins dependent on older versions).</li>
<li>If you use <a href="http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/" target="_blank">my technique for isolating your code from ASP.NET AJAX’s “.d”</a>, you will still need a method for deserializing JSON in the dataFilter.</li>
</ul>
<p>Speaking of that last point, if you’re using jQuery with ASP.NET AJAX services, be sure to watch out for the next post in this (accidental) series. There is at least one more productive step left in improving this workflow that I have been using in my projects and want to share with you soon.</p>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/07/07/improving-jquery-json-performance-and-security/">Improving jQuery’s JSON performance and security</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2009/07/07/improving-jquery-json-performance-and-security/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Never worry about ASP.NET AJAX&#8217;s .d again</title>
		<link>http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/</link>
		<comments>http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 05:00:48 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/?p=883</guid>
		<description><![CDATA[When I recently received this message from a frustrated reader:
After hours and hours of slamming my head into the desk it turns out it was the darn &#34;d&#34; in the response. My home computer is on .NET 2.0 and my work computer is on 3.5. Jimminie Christmas!
I realized that the “.d” introduced in ASP.NET AJAX [...]<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/">Never worry about ASP.NET AJAX&#8217;s .d again</a></p>
]]></description>
			<content:encoded><![CDATA[<p>When I recently received this message from a frustrated reader:</p>
<blockquote><p>After hours and hours of slamming my head into the desk it turns out it was the darn &quot;d&quot; in the response. My home computer is on .NET 2.0 and my work computer is on 3.5. <strong>Jimminie Christmas</strong>!</p></blockquote>
<p>I realized that the “.d” introduced in ASP.NET AJAX 3.5’s JSON responses is still all too common a stumbling block when <a target="_blank" href="http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/">calling ASP.NET AJAX services through a library such as jQuery</a>. In fact, with jQuery’s popularity among ASP.NET developers on the rise, this appears to have <strong>become an even more frequent problem</strong>.</p>
<p>Since a lot of people are having trouble with it, I want to share one method you can use to completely isolate your code from the problem. If you bake this into an $.ajax() code snippet or otherwise use it as a template for calling ASP.NET AJAX services in jQuery, you should never have to think or worry about the “.d” again.</p>
<p>In this post, I will show you <strong>how to detect the “.d”</strong> and how you can <strong>completely isolate your $.ajax success handler from it</strong>.</p>
<h3>“.d” what?</h3>
<p>If you aren’t familiar with the “.d” I’m referring to, it is simply a security feature that Microsoft added in ASP.NET 3.5’s version of ASP.NET AJAX. By encapsulating the JSON response within a parent object, the framework helps protect against <a href="http://haacked.com/archive/2009/06/25/json-hijacking.aspx" target="_blank">a particularly nasty XSS vulnerability</a>.</p>
<p>Before ASP.NET 3.5, “ScriptServices” and page methods returned their data at the top level of the JSON response, like this:</p>
<p><img title="2.0 JSON Response" border="0" alt="2.0 JSON Response in Firebug" src="http://encosia.com/blog/wp-content/uploads/2009/02/20-json-response.png" width="490" height="146" /></p>
<p>In ASP.NET 3.5 and later, the same server-side code returns this:</p>
<p><img title="3.5 JSON Response" border="0" alt="3.5 JSON Response in Firebug" src="http://encosia.com/blog/wp-content/uploads/2009/02/35-json-response.png" width="490" height="146" /></p>
<p>For more information about the change and <em>why</em> the change is a good one, be sure to see my earlier post: <a href="http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/" target="_blank">A breaking change between versions of ASP.NET AJAX</a>.</p>
<p>However, what my previous post lacks is a solution for mitigating the inconsistency entirely. Using different client-side code against 2.0 and 3.5 based services is workable, but far from ideal. <strong>Wouldn’t it be nicer to not have to worry about it?</strong></p>
<h3>Determining whether or not the “.d” is there</h3>
<p>In order to isolate ourselves from the “.d”, we first need a reliable way to test for its presence. Though JavaScript provides several methods for determining this, I suggest hasOwnProperty, <a href="http://encosia.com/2009/02/16/review-the-best-javascript-book-i%E2%80%99ve-read/" rel="nofollow" target="_blank">as recommended by Douglas Crockford</a>.</p>
<p>By using hasOwnProperty, your code is protected against <a href="http://encosia.com/2008/09/28/avoid-this-tricky-conflict-between-aspnet-ajax-and-jquery/" target="_blank">unexpected changes to an object’s prototype chain</a>. Though it is an unlikely problem to encounter, it’s always best to code defensively in JavaScript. The browser is a hostile environment!</p>
<p>Using hasOwnProperty to test for “.d”, you might end up with something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
  url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;WebService.asmx/MethodName&quot;</span><span style="color: #339933;">,</span>
  data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;{}&quot;</span><span style="color: #339933;">,</span>
  contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json; charset=utf-8&quot;</span><span style="color: #339933;">,</span>
  dataType<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #339933;">,</span>
  success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>msg.<span style="color: #660066;">hasOwnProperty</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;d&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #006600; font-style: italic;">// Leave the .d behind and pass the rest of </span>
      <span style="color: #006600; font-style: italic;">//  the JSON object forward.</span>
      DoSomething<span style="color: #009900;">&#40;</span>msg.<span style="color: #660066;">d</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
      <span style="color: #006600; font-style: italic;">// No .d; no transformation necessary.</span>
      DoSomething<span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> DoSomething<span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Do something with the response data here.</span>
  <span style="color: #006600; font-style: italic;">//  Expect it to consistently have no .d.</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This code <em>will</em> perform identically against any version of ASP.NET AJAX.</p>
<p>Unfortunately, this might still get in your way. You may not always want to use the response in a call to another function, and you’ll have to remember the conditional every time you write a success handler.</p>
<h3>Don’t make me think</h3>
<p>I prefer a solution that doesn’t touch the success handler at all. Then, you’re free to integrate the “.d” handling into a generic $.ajax code snippet in Visual Studio and/or easily copy-paste it between files without modification.</p>
<p>Luckily, jQuery provides a mechanism that allows us to do just that: <strong>dataFilter</strong>.</p>
<p>The dataFilter parameter to $.ajax allows you to arbitrarily transform a response <em>just before</em> the success handler fires. Specifically tailored to this sort of situation, it passes response data into a callback function, captures the return value of that callback, and then passes the modified data into your success handler.</p>
<p>Hence, you can forever stop worrying about that pesky “.d” like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
  url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;WebService.asmx/MethodName&quot;</span><span style="color: #339933;">,</span>
  data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;{}&quot;</span><span style="color: #339933;">,</span>
  contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json; charset=utf-8&quot;</span><span style="color: #339933;">,</span>
  dataFilter<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// This boils the response string down </span>
    <span style="color: #006600; font-style: italic;">//  into a proper JavaScript Object().</span>
    <span style="color: #003366; font-weight: bold;">var</span> msg <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'('</span> <span style="color: #339933;">+</span> data <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// If the response has a &quot;.d&quot; top-level property,</span>
    <span style="color: #006600; font-style: italic;">//  return what's below that instead.</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>msg.<span style="color: #660066;">hasOwnProperty</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'d'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #000066; font-weight: bold;">return</span> msg.<span style="color: #660066;">d</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
      <span style="color: #000066; font-weight: bold;">return</span> msg<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  success<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>msg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// This will now output the same thing </span>
    <span style="color: #006600; font-style: italic;">//  across any current version of .NET.</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>msg.<span style="color: #660066;">foo</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now, regardless which of these JSON forms the server returns:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// ASP.NET 2.0 with the ASP.NET AJAX Extensions installed.</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'foo'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'bar'</span><span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// ASP.NET 3.5 and 4.0.</span>
<span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'d'</span><span style="color: #339933;">:</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'foo'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'bar'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>Your success handler will simply receive this consistent JSON object every time:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'foo'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'bar'</span><span style="color: #009900;">&#125;</span></pre></div></div>

<h3>dataType: none of your business</h3>
<p>It&#8217;s important to note the removal of the dataType parameter in the $.ajax() code above. This is required in order to prevent a double-eval of service responses containing only a single string.</p>
<p>Internally, jQuery uses a combination of the dataType parameter and the implicit type the response. If the dataType is &quot;json&quot; and typeof(response) is “string”, then jQuery uses eval() to deserialize the response.</p>
<p>In the example above, manually deserializing the response in dataFilter results in it being of type Object, jQuery leaves it alone, and our dataFilter’d object makes its way back to the success callback either way.</p>
<p>However, if the dataType is set to “json” and the “.d” sanitized response happens to be of JavaScript type “string”, jQuery will assume that it is a JSON response from the server and still needs to be deserialized. That will throw an error at best.</p>
<p>The solution is to simply drop the dataType parameter from the $.ajax() call. It is only needed for purposes of instructing jQuery how to deserialize the response, and we’re handling that ourselves now.</p>
<p>Thanks to Brett <a href="#comment-35702">for pointing this out</a>.</p>
<h3>Wait, isn’t eval() supposed to be evil?</h3>
<p>If the eval() usage gives you pause, don’t worry. For now (as of jQuery 1.3.2), this is the same mechanism that jQuery uses to deserialize JSON too. Though eval() <em>is</em> potentially evil, <strong>it is still a necessary evil in many browsers</strong>.</p>
<p>In my next post, I’ll show you how to modify this to leverage a native browser implementation of JSON.parse instead of eval(), available in some newer browsers.</p>
<p>That post is available now: <a href="http://encosia.com/2009/07/07/improving-jquery-json-performance-and-security/">Improving jQuery&#8217;s JSON performance and security</a>.</p>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/">Never worry about ASP.NET AJAX&#8217;s .d again</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2009/06/29/never-worry-about-asp-net-ajaxs-d-again/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Hear me talk about jQuery on the Polymorphic Podcast</title>
		<link>http://encosia.com/2009/06/20/hear-me-talk-about-jquery-on-the-polymorphic-podcast/</link>
		<comments>http://encosia.com/2009/06/20/hear-me-talk-about-jquery-on-the-polymorphic-podcast/#comments</comments>
		<pubDate>Sat, 20 Jun 2009 17:12:28 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/2009/06/20/hear-me-talk-about-jquery-on-the-polymorphic-podcast/</guid>
		<description><![CDATA[As a longtime listener myself, I was eager when Craig asked me to come on the Polymorphic Podcast to talk about jQuery. I’ve always enjoyed how he doesn’t shy away from talking about HTML and JavaScript, which is still too uncommon in the .NET world.
With that in mind, I knew we’d be able to have [...]<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/06/20/hear-me-talk-about-jquery-on-the-polymorphic-podcast/">Hear me talk about jQuery on the Polymorphic Podcast</a></p>
]]></description>
			<content:encoded><![CDATA[<p>As a longtime listener myself, I was eager when Craig asked me to come on the Polymorphic Podcast to talk about jQuery. I’ve always enjoyed how he doesn’t shy away from talking about HTML and JavaScript, which is still too uncommon in the .NET world.</p>
<p>With that in mind, I knew we’d be able to have a great conversation about jQuery and the concerns that ASP.NET developers run into when using it. I really enjoyed recording the show, and think it turned out pretty well. I hope you’ll enjoy it too:</p>
<p><a href="http://polymorphicpodcast.com/shows/jquery/" target="_blank">Polymorphic Podcast: jQuery Secrets with Dave Ward</a></p>
<p> If you haven’t yet, I highly recommend <a href="http://polymorphicpodcast.com/podcast/feed/" target="_blank">subscribing to Craig’s podcast</a>. There are some real gems in his <a href="http://polymorphicpodcast.com/shows/" target="_blank">previous shows</a> too, so check those out as well.</p>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/06/20/hear-me-talk-about-jquery-on-the-polymorphic-podcast/">Hear me talk about jQuery on the Polymorphic Podcast</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2009/06/20/hear-me-talk-about-jquery-on-the-polymorphic-podcast/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>11 keystrokes that made my jQuery selector run 10x faster</title>
		<link>http://encosia.com/2009/06/09/11-keystrokes-that-made-my-jquery-selector-run-10x-faster/</link>
		<comments>http://encosia.com/2009/06/09/11-keystrokes-that-made-my-jquery-selector-run-10x-faster/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 18:45:31 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/?p=877</guid>
		<description><![CDATA[As an ASP.NET developer working on the client-side, one problem you’ll encounter is how to reference the HTML elements that ASP.NET web controls generate. All too often, you find yourself wasting time trying to reference TextBox1, when the element is actually rendered as ctl00_panel1_wizard1_TextBox1.
Much has been written about this, including a post of my own, [...]<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/06/09/11-keystrokes-that-made-my-jquery-selector-run-10x-faster/">11 keystrokes that made my jQuery selector run 10x faster</a></p>
]]></description>
			<content:encoded><![CDATA[<p>As an ASP.NET developer working on the client-side, one problem you’ll encounter is how to reference the HTML elements that ASP.NET web controls generate. All too often, you find yourself wasting time trying to reference TextBox1, when the element is actually rendered as ctl00_panel1_wizard1_TextBox1.</p>
<p>Much has been written about this, <a href="http://encosia.com/2007/08/08/robust-aspnet-control-referencing-in-javascript/">including a post of my own</a>, so I won’t go into detail about many of the workarounds. Instead, I want to take a closer look at the performance drawbacks of one popular solution: <a href="http://docs.jquery.com/Selectors/attributeEndsWith#attributevalue" target="_blank">the [attribute$=value] selector</a>.</p>
<p>By specifying <strong>id</strong> as the <strong>attribute</strong> in this selector, you can avoid ASP.NET’s ClientID issues completely. No matter what the framework prefixes your rendered elements with, they still “end with” the ID you specify at design time. This makes the “ends with” selector a convenient alternative to injecting a control’s ClientID property via angle-brackets.</p>
<p>However, are we<strong> trading performance for this convenience</strong>? If so, <strong>how much</strong>?</p>
<p>When <a href="http://weblogs.asp.net/craigshoemaker/" target="_blank">Craig Shoemaker</a> asked that question while interviewing me for an upcoming episode of <a href="http://polymorphicpodcast.com/" target="_blank">Polymorphic Podcast</a>, I realized I didn’t know the answer as clearly as I’d like. So, I decided to do a bit of benchmarking.</p>
<p>In this post, I’ll share <strong>the results of that benchmarking</strong>, and show you one way to <strong>significantly improve the performance</strong> of this convenient selector.</p>
<h3>The test scenario</h3>
<p>One difficulty when analyzing selector performance is that <strong>they all perform well on small test pages</strong>. Most performance issues aren’t readily apparent until a page grows in complexity and contains many elements. This can easily leave you overly confident in techniques that survive a simple proof of concept, but don’t scale well to practical usage.</p>
<p>Rather than construct a complex demonstration page from scratch to test against, I decided to use an existing page. With over 160 comments at the time of writing (and testing), <a href="http://encosia.com/downloads/highslide-js-net/">the Highslide JS .NET project page</a> is an ideal candidate. Its 1,000+ DOM elements are well suited to expose poorly performing selectors.</p>
<p>Enclosing each comment on the page, there’s a div like this one:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;div-comment-35496&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;comment&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #060; font-style: italic;">&lt;!-- Comment content here --&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div&gt;</span></span></pre></div></div>

<p>If you imagine that the “div-“ prefix is “ctl00_”, these IDs are a great substitute for the ClientIDs that ASP.NET controls render within naming containers.</p>
<p>So for purposes of testing, I attempted to select the element <strong>div-comment-35496</strong> on that page, assuming that I knew its ID of <strong>comment-35496</strong> at design time and that the “div-“ prefix was added at run time. This is identical to the process of selecting the div rendered by an ASP.NET Panel control within a Content Page, for example.</p>
<h3>Test methodology</h3>
<p>To benchmark each selector, I used the following JavaScript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> iterations <span style="color: #339933;">=</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> totalTime <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Repeat the test the specified number of iterations.</span>
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> iterations<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Record the starting time, in UTC milliseconds.</span>
  <span style="color: #003366; font-weight: bold;">var</span> start <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Execute the selector. The result does not need</span>
  <span style="color: #006600; font-style: italic;">//  to be used or assigned to determine how long </span>
  <span style="color: #006600; font-style: italic;">//  the selector itself takes to run.</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'[id$=comment-35496]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Record the ending time, in UTC milliseconds.</span>
  <span style="color: #003366; font-weight: bold;">var</span> end <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// Determine how many milliseconds elapsed and</span>
  <span style="color: #006600; font-style: italic;">//  increment the test's totalTime counter.</span>
  totalTime <span style="color: #339933;">+=</span> <span style="color: #009900;">&#40;</span>end <span style="color: #339933;">-</span> start<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Report the average time taken by one iteration.</span>
<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>totalTime <span style="color: #339933;">/</span> iterations<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This simply executes the selector 100 times, recording how many milliseconds each run takes, and then determines the average.</p>
<p>I had originally recorded and displayed an array of each individual time, but found there was very little variation and stopped tracking each execution. The average is good enough for these purposes.</p>
<p>For each selector, I ran the test five times and then averaged the results, resulting in an average across 500 separate executions in semi-isolated batches. Then, I repeated the process for each major browser.</p>
<p>CERN probably won’t be flying me out to work on the LHC with this level of rigor, but it’s accurate enough for measuring the relative performance change between different selectors.</p>
<h3>The baseline</h3>
<p>jQuery’s <a href="http://docs.jquery.com/Selectors/id#id" target="_blank">#id selector</a> leverages browsers’ native <a href="http://msdn.microsoft.com/en-us/library/ms536437%28VS.85%29.aspx" rel="nofollow" target="_blank">getElementById</a> routine. Though slower than calling getElementById directly, this is a very fast way to reference our div as a jQuery object:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#div-comment-35496'</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>As you may expect, this browser assisted selector is fastest. In fact, <strong>every major browser consistently performed this in less than one millisecond</strong> in my testing. Most in less than <em>a third of a millisecond</em>.</p>
<p>To safely use this selector in ASP.NET, we have to manually inject the a control’s ClientID property. Otherwise, any naming container added, removed, or renamed would break our client-side code.</p>
<p>You’ve probably seen that accomplished like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#&lt;%= comment-35496.ClientID %&gt;'</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>It looks messy and requires a bit more effort, but it’s <strong>fast</strong>.</p>
<p>ASP.NET 4.0’s <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.clientidmode%28VS.100%29.aspx" rel="nofollow" target="_blank">ClientIDMode property</a> promises to eliminate this inconvenience in the long-term, but we’re stuck with it for now. For that matter, with many projects still using ASP.NET 1.x and 2.0, slow to adopt the latest version, we may be stuck with the problem for quite some time to come.</p>
<h3>Convenience</h3>
<p>To avoid the messy work of manually injecting ASP.NET’s rendered ClientIDs, you may have seen the suggestion that this is an easier way:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'[id$=comment-35496]'</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>Indeed, this will successfully select the element that we’re after. Since its ID is div-comment-35496, searching for an element whose ID “ends with” comment-35496 works as desired.</p>
<p>Eliminating the angle-brackets is aesthetically pleasing and it’s less up-front work, but what about performance?</p>
<p>jQuery’s selector engine implements “ends with” by performing this test on every element in question, where value is the attribute you’ve specified and check is the string that you’re searching for:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">value.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span>value.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> check.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> check</pre></div></div>

<p>That’s not so bad if you’re only doing it once, but doing it <strong>for every element on the page</strong> is a different story. Remember our test page has <em>thousands</em> of elements.</p>
<p>What’s worse, jQuery has no way to know that only one element should match the pattern. So, it must continue iterating through to the end of the page, even after locating the single element that we’re actually interested in.</p>
<p>How bad is it? Over the course of several hundred executions on the test page, I obtained these average speeds for a single $= selector execution in each browser:</p>
<p><img src="http://encosia.com/blog/wp-content/uploads/2009/06/ends-with-comparison.png" width="492" height="199" /></p>
<p>The Chrome numbers are unsurprising, given its speedy <a href="http://code.google.com/p/v8/" target="_blank">V8 JavaScript engine</a>. IE8 and Firefox 3.5 perform admirably too. These newer browsers all executed the selector very <strong>nearly as quickly as document.getElementById</strong>.</p>
<p>However, IE7 and Firefox 3.0 are <strong>substantially slower</strong> when executing the “ends with” selector. Remembering the non-trivial difference that Firebug made in <a href="http://weblogs.asp.net/yuanjian/archive/2009/03/22/json-performance-comparison-of-eval-new-function-and-json.aspx" target="_blank">this interesting post about JSON parsing speeds</a>, I also tested with and without Firebug enabled in Firefox 3.0 (which turned out to be a significant factor here too).</p>
<p>Even though we’re only talking about milliseconds, the penalty in older browsers is too large to ignore — especially when the vast majority of users are still on IE6, IE7, or Firefox 3.0, not the new generation of faster browsers.</p>
<h3>Convenience optimized</h3>
<p>Remembering that the #id selector is quick because it leverages the native speed of getElementById, we can help jQuery execute the $= selector more efficiently.</p>
<p>If we modify the selector to descend from an HTML tag before performing the “ends with” search, jQuery can use <a href="http://msdn.microsoft.com/en-us/library/ms536439%28VS.85%29.aspx" rel="nofollow" target="_blank">getElementsByTagName</a> to pre-filter the set of elements to search within. Since getElementsByTagName is a native browser routine, it is much faster than jQuery’s interpreted selector engine.</p>
<p>For example, since we know the element we’re after is a div, we could optimize the previous $= selector like this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div[id$=comment-35457]'</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>The benefit is substantial:</p>
<p><img src="http://encosia.com/blog/wp-content/uploads/2009/06/ends-with-descending-from-div-comparison.png" width="492" height="199" /></p>
<p>The optimized selector runs more than twice as quickly in IE7 and Firefox 3.0!</p>
<p>Along the same lines, <a href="http://sizzlejs.com/" rel="nofollow" target="_blank">jQuery’s Sizzle engine</a> is able to select CSS classes faster than it can perform substring searches within arbitrary attributes. So, the selector can be further optimized by descending from both an HTML tag <em>and</em> a CSS class.</p>
<p>Since the particular div we’re testing against has a CSS class of <em>comment</em>, let’s try this selector:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.comment[id$=comment-35457]'</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>The results?</p>
<p><img src="http://encosia.com/blog/wp-content/uploads/2009/06/ends-with-descending-from-css-comparison.png" width="492" height="199" /></p>
<p>IE7 doesn’t improve much, but Firefox 3.0 shows another excellent increase in its performance. The reason that Firefox shines here is that <a href="http://ejohn.org/blog/getelementsbyclassname-in-firefox-3/" target="_blank">it implements a native getElementsByClassName routine</a> that IE7 doesn’t (though IE8 does).</p>
<p>While slower than the getElementById powered #id selector, <strong>these optimizations have given us a 3-10x speed increase</strong> while referencing exactly the same element as the original $= selector. That’s a pretty good return on the investment of typing a measly eleven characters (div.comment) in front of the selector!</p>
<h3>A mountain out of a molehill?</h3>
<p>This post may seem like a lot of effort to spend on a seemingly tiny performance differential. In fact, I almost considered leaving this one on the shelf, because it’s often difficult to sell the importance of milliseconds.</p>
<p>But, you know what? <strong>Milliseconds count! </strong>A performance difference of a few dozen milliseconds is a perceptible delay. A few hundred will alienate your users.</p>
<p>Research has consistently shown a strong correlation between fast sites and <a href="http://www.bizjournals.com/atlanta/stories/2008/12/15/daily6.html" rel="nofollow" target="_blank">higher conversion rates</a>, <a href="http://glinden.blogspot.com/2006/11/marissa-mayer-at-web-20.html" target="_blank">more user actions per visit</a>, and <a href="http://web.archive.org/web/20040913083444/http://developer.netscape.com/viewsource/bickford_wait.htm" rel="nofollow" target="_blank">user satisfaction</a>. Compounded across the thousands or millions of times a particular function in your application will be used, it is absolutely worthwhile to invest a few minutes in order to save a few milliseconds.</p>
<h3>Conclusion</h3>
<p>I hope you’ve found this information useful. Without hard data, it’s difficult to decide which optimizations are premature and which are worthwhile. Especially since your page is likely to grow more complex over time, I think the data clearly shows that selectors which don’t directly target an ID should <em>always</em> descend from an HTML tag when possible.</p>
<p>Perhaps the most important takeaway is that you must keep in mind how easy it is to write one succinct line of jQuery code that results in a non-trivial loop. The real danger lies in putting a selector like $= within a loop yourself, unaware that what appears to be a simple loop is actually a relatively sluggish nested loop.</p>
<p>The other lesson here is that if speed is crucial, you should inject ClientIDs and use the #id selector (as in the baseline shown above). Even the most optimized “ends with” selector in this post still runs at least one order of magnitude slower than the direct #id selector.</p>
<p>Instead of simply posting that div.class[id$=id] is faster than [id$=id], I wanted to explain the sequence of events that led me to that determination. Armed with knowledge of how I optimized the “ends with” selector, I hope that you have a few new optimization tricks up your sleeve now.</p>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/06/09/11-keystrokes-that-made-my-jquery-selector-run-10x-faster/">11 keystrokes that made my jQuery selector run 10x faster</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2009/06/09/11-keystrokes-that-made-my-jquery-selector-run-10x-faster/feed/</wfw:commentRss>
		<slash:comments>38</slash:comments>
		</item>
		<item>
		<title>What ASP.NET developers should know about jQuery</title>
		<link>http://encosia.com/2009/05/13/what-aspnet-developers-should-know-about-jquery/</link>
		<comments>http://encosia.com/2009/05/13/what-aspnet-developers-should-know-about-jquery/#comments</comments>
		<pubDate>Wed, 13 May 2009 17:10:41 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/?p=855</guid>
		<description><![CDATA[As much as I enjoyed attending MIX09 this year, it wasn’t a difficult decision when Karsten asked me to write an article for the MIX Online site.
Reading this here, there’s a good chance the article is targeted below the amount of jQuery expertise you already have. However, it’s been brought to my attention that some [...]<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/05/13/what-aspnet-developers-should-know-about-jquery/">What ASP.NET developers should know about jQuery</a></p>
]]></description>
			<content:encoded><![CDATA[<p>As much as I enjoyed attending <a href="http://live.visitmix.com/" target="_blank">MIX09</a> this year, it wasn’t a difficult decision when <a href="http://visitmix.com/About/karstenj" target="_blank">Karsten</a> asked me to write an article for the MIX Online site.</p>
<p>Reading this here, there’s a good chance the article is targeted below the amount of jQuery expertise you already have. However, it’s been brought to my attention that some readers have found it useful for sending to their more JavaScript-phobic coworkers.</p>
<p>So, I decided that it’s worth mentioning here after all:</p>
<blockquote><p>It’s hard to believe that <strong>JavaScript is already well over a decade old</strong>. Often relegated to marginal tasks in its early years, JavaScript has grown to become a pillar of modern web development. With the current popularity of DHTML and AJAX, it can be difficult to find a site that <strong>doesn’t</strong> use JavaScript anymore. One of the driving forces behind JavaScript’s newfound popularity is a proliferation of JavaScript frameworks, such as <strong>jQuery</strong>.</p>
<p>&#160;</p>
<p>Why?</p></blockquote>
<p><a class="more-link" href="http://visitmix.com/Opinions/What-ASPNET-Developers-Should-Know-About-jQuery" target="_blank">Click here to continue reading this article on the MIX Online site &raquo;</a></p>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/05/13/what-aspnet-developers-should-know-about-jquery/">What ASP.NET developers should know about jQuery</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2009/05/13/what-aspnet-developers-should-know-about-jquery/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How I handle JSON dates returned by ASP.NET AJAX</title>
		<link>http://encosia.com/2009/04/27/how-i-handle-json-dates-returned-by-aspnet-ajax/</link>
		<comments>http://encosia.com/2009/04/27/how-i-handle-json-dates-returned-by-aspnet-ajax/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 15:22:44 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/?p=853</guid>
		<description><![CDATA[
The problem of how to handle dates in JSON is one of the more troublesome issues that may arise when directly calling ASP.NET AJAX web services and page methods.
Unlike every other data type in the language, JavaScript offers no declarative method for expressing a Date. Consequently, embedding them within JSON requires a bit of fancy [...]<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/04/27/how-i-handle-json-dates-returned-by-aspnet-ajax/">How I handle JSON dates returned by ASP.NET AJAX</a></p>
]]></description>
			<content:encoded><![CDATA[<p><img style="border: 1px solid #000;" title="image" border="0" alt="A calendar" src="http://encosia.com/blog/wp-content/uploads/2009/04/calendar-blocks.jpg" width="490" height="215" /></p>
<p>The problem of how to handle dates in JSON is one of the more troublesome issues that may arise when <em>directly</em> calling ASP.NET AJAX web services and page methods.</p>
<p>Unlike every other data type in the language, <strong>JavaScript offers no declarative method for expressing a Date</strong>. Consequently, embedding them within JSON requires a bit of fancy footwork. Since the question of how I handle this problem is something asked often in emails and in comments on other posts here, I want to address the topic with its own post.</p>
<p>To that end, I will attempt to explain <strong>what exactly the problem is</strong> with dates in JSON, <strong>how ASP.NET AJAX solves it</strong>, and <strong>my alternative solution</strong> that I believe is easier and works just as well in most cases.</p>
<h3>What’s the problem?</h3>
<p>The fundamental problem is that JavaScript does not provide a way to declaratively express <a href="http://www.w3schools.com/jS/js_obj_date.asp" rel="nofollow" target="_blank">Date objects</a>. You may previously have seen this <a href="http://www.nikhilk.net/DateSyntaxForJSON.aspx" target="_blank">described as (the lack of) <strong>a Date literal</strong></a>.</p>
<p>What are literals? To illustrate, these are literals for several other data types:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// String</span>
<span style="color: #3366CC;">'foo'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Number</span>
<span style="color: #CC0000;">3.14</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Boolean</span>
<span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Array</span>
<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">7</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Object</span>
<span style="color: #009900;">&#123;</span> pi<span style="color: #339933;">:</span> <span style="color: #CC0000;">3.14</span><span style="color: #339933;">,</span> phi<span style="color: #339933;">:</span> <span style="color: #CC0000;">1.62</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Unfortunately, when it comes to dates, the lack of a literal means that the only way to create one is by explicitly initializing a Date object:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Correct.</span>
<span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'4/26/09'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Correct (the month is 0 indexed, hence the 3).</span>
<span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2009</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">26</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Incorrect. This is a string, not a Date.</span>
<span style="color: #3366CC;">'4/26/09'</span><span style="color: #339933;">;</span></pre></div></div>

<p>While this limitation is fine when writing client-side JavaScript code, it leaves us without a good way to transmit dates within JSON objects.</p>
<h3>How ASP.NET AJAX handles it</h3>
<p>While the lack of a date literal is a problem, it’s certainly not without solution.</p>
<p>In fact, ASP.NET AJAX <strong>already handles this</strong> if you’re using MicrosoftAjax.js to call your services. You may not have even noticed as server-side DateTime values are transparently converted into JavaScript Date objects on the client-side.</p>
<p>For example, consider this web service:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Web</span></span>.<span style="color: #0000FF;">Script</span>.<span style="color: #0000FF;">Services</span>.<span style="color: #0000FF;">ScriptService</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> DateService <span style="color: #008000;">:</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">Services</span></span>.<span style="color: #0000FF;">WebService</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #000000;">&#91;</span>WebMethod<span style="color: #000000;">&#93;</span>
  <span style="color: #0600FF;">public</span> DateTime GetDate<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> DateTime<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">2009</span>, <span style="color: #FF0000;">4</span>, <span style="color: #FF0000;">26</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>If you <a href="http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/" target="_blank">consume that web service with jQuery</a> (or any method that circumvents the ScriptManager), you’ll find that ASP.NET AJAX serializes the DateTime as an escaped JavaScript Date initializer:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;d&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\/</span>Date(1240718400000)<span style="color: #000099; font-weight: bold;">\/</span>&quot;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p><em>Note: If you&#8217;re unsure about why the &#8220;d&#8221; is there, be sure to see <a href="http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/">my recent post about this security feature which was added in ASP.NET 3.5</a>.</em></p>
<p>On the client-side, MicrosoftAjax.js uses a regular expression to isolate any Date constructors and then eval() to initialize Date objects. The end result is that proper JavaScript Date objects are instantiated for every DateTime value returned.</p>
<p>However, if you’re <em>not</em> using MicrosoftAjax.js (i.e. the ScriptManager) to call your services, you’ve got a bit of a mess to decode. You can <a href="http://weblogs.asp.net/bleroy/archive/2008/01/18/dates-and-json.aspx" target="_blank">use regex machinations to work around the problem</a>, but is that really necessary?</p>
<h3>How I handle it</h3>
<p>Consider <em>why</em> you want to send a DateTime to the client-side to begin with. Most often, you’re <strong>displaying a string representation of it</strong> and have no need for the proper JavaScript Date object.</p>
<p>What’s more, if you end up with a JavaScript Date object, you’ll probably use additional code or a JavaScript library to <strong>display it in a user-friendly format</strong>.</p>
<p>As much as I appreciate a clever workaround, I’d much rather avoid the problem completely. Rather than jump through all of these hoops to instantiate a JavaScript Date object on the client-side and then format it, <strong>I suggest simply returning a formatted string</strong>.</p>
<p>For example, we might modify the previous example like so:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>System.<span style="color: #660066;">Web</span>.<span style="color: #660066;">Script</span>.<span style="color: #660066;">Services</span>.<span style="color: #660066;">ScriptService</span><span style="color: #009900;">&#93;</span>
<span style="color: #003366; font-weight: bold;">public</span> <span style="color: #003366; font-weight: bold;">class</span> DateService <span style="color: #339933;">:</span> System.<span style="color: #660066;">Web</span>.<span style="color: #660066;">Services</span>.<span style="color: #660066;">WebService</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#91;</span>WebMethod<span style="color: #009900;">&#93;</span>
  <span style="color: #003366; font-weight: bold;">public</span> string GetDate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> DateTime<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2009</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">26</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ToLongDateString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now, calling the service will return this JSON:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;d&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Sunday, April 26, 2009&quot;</span><span style="color: #009900;">&#125;</span></pre></div></div>

<p>No more regular expressions. No more JavaScript Date objects. No more worrying about formatting the data on the client-side.</p>
<p>Even better, no functionality is lost. If we need to instantiate Dates, we still can.</p>
<h3>Still want Dates?</h3>
<p>Even if you <em>do</em> end up needing JavaScript Date objects, <strong>DateTime strings are sufficient for instantiating them</strong>. JavaScript’s Date constructor is very flexible:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// ASP.NET AJAX form</span>
<span style="color: #003366; font-weight: bold;">var</span> foo <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1240718400000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// DateTime.ToLongDateString() form</span>
<span style="color: #003366; font-weight: bold;">var</span> bar <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Sunday, April 26, 2009'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// DateTime.ToShortDateString() form</span>
<span style="color: #003366; font-weight: bold;">var</span> baz <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'4/26/2009'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// true!</span>
foo <span style="color: #339933;">===</span> bar <span style="color: #339933;">===</span> baz<span style="color: #339933;">;</span></pre></div></div>

<p>By delaying string-to-Date conversions until truly necessary, we save effort on the server- and client-side. Not only that, but we have the option of retaining both the formatted string <em>and</em> the JavaScript Date to use as desired.</p>
<p>The best of both worlds.</p>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/04/27/how-i-handle-json-dates-returned-by-aspnet-ajax/">How I handle JSON dates returned by ASP.NET AJAX</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2009/04/27/how-i-handle-json-dates-returned-by-aspnet-ajax/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Using complex types to make calling services less&#8230; complex</title>
		<link>http://encosia.com/2009/04/07/using-complex-types-to-make-calling-services-less-complex/</link>
		<comments>http://encosia.com/2009/04/07/using-complex-types-to-make-calling-services-less-complex/#comments</comments>
		<pubDate>Tue, 07 Apr 2009 08:33:22 +0000</pubDate>
		<dc:creator>Dave Ward</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://encosia.com/?p=849</guid>
		<description><![CDATA[A detailed examination of how jQuery can call ASP.NET AJAX web services (or page methods) with complex types as parameters, to simplify the process of serializing and sending several fields of data at a time.<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/04/07/using-complex-types-to-make-calling-services-less-complex/">Using complex types to make calling services less&#8230; complex</a></p>
]]></description>
			<content:encoded><![CDATA[<p>So far, my examples of using jQuery to interact with ASP.NET AJAX services have avoided <strong>passing complex data to the server</strong> during the request. This has been intentional, because I didn’t want to over-complicate the examples.</p>
<p>For primarily read-only scenarios, like <a href="http://encosia.com/2008/06/26/use-jquery-and-aspnet-ajax-to-build-a-client-side-repeater/">the RSS reader examples</a>, passing just a few simple values to the service is often all you need. However, this scalar approach quickly becomes untenable when making real-world service calls.</p>
<p>In this post, I’m going to show you how <strong>passing complex types </strong><strong>to the server</strong> helps alleviate complexity, how <strong>json2.js and a data transfer object (DTO) facilitates this</strong>, and how to <strong>use jQuery to very easily build the DTO</strong>.</p>
<h3>Setting the stage</h3>
<p>Let’s say that we want to improve the performance of a data entry application used to add <strong>Person</strong> records to a database. The original version was developed quickly using an UpdatePanel, <a href="http://encosia.com/2007/07/11/why-aspnet-ajax-updatepanels-are-dangerous/">but performs poorly</a>. Not wanting the Person-data-entry-department to spend more time waiting than they do typing, we must find a way to improve the application’s performance.</p>
<p>Having done some research, we might decide that replacing the UpdatePanel with <a href="http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/">jQuery and a web service would be a great way to speed things up</a>.</p>
<h3>A foundation and a facade</h3>
<p>The properties of the existing <strong>Person</strong> class could be as simple as this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Person
<span style="color: #000000;">&#123;</span>
  <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> FirstName <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
  <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> LastName <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
  <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Address <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
  <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> City <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
  <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> State <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
  <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Zip <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
  <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Add<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
  <span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Magic happens here.</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The original entry form probably used TextBox controls, but that will no longer be necessary. Regular HTML input elements carry less overhead and ensure that we don’t have to worry about <a href="http://encosia.com/2007/08/08/robust-aspnet-control-referencing-in-javascript/">ClientID issues</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #060; font-weight: bold;">&lt;</span>label <span style="color: #909; font-weight: bold;">for</span><span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;FirstName&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>First Name<span style="color: #060; font-weight: bold;">:&lt;/</span>label<span style="color: #060; font-weight: bold;">&gt;</span>
<span style="color: #060; font-weight: bold;">&lt;</span>input type<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;text&quot;</span> id<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;FirstName&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #060; font-weight: bold;">&lt;</span>label <span style="color: #909; font-weight: bold;">for</span><span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;LastName&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>Last Name<span style="color: #060; font-weight: bold;">:&lt;/</span>label<span style="color: #060; font-weight: bold;">&gt;</span>
<span style="color: #060; font-weight: bold;">&lt;</span>input type<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;text&quot;</span> id<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;LastName&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #060; font-weight: bold;">&lt;</span>label <span style="color: #909; font-weight: bold;">for</span><span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Address&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>Address<span style="color: #060; font-weight: bold;">:&lt;/</span>label<span style="color: #060; font-weight: bold;">&gt;</span>
<span style="color: #060; font-weight: bold;">&lt;</span>input type<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;text&quot;</span> id<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Address&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #060; font-weight: bold;">&lt;</span>label <span style="color: #909; font-weight: bold;">for</span><span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;City&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>City<span style="color: #060; font-weight: bold;">:&lt;/</span>label<span style="color: #060; font-weight: bold;">&gt;</span>
<span style="color: #060; font-weight: bold;">&lt;</span>input type<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;text&quot;</span> id<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;City&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #060; font-weight: bold;">&lt;</span>label <span style="color: #909; font-weight: bold;">for</span><span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;State&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>State<span style="color: #060; font-weight: bold;">:&lt;/</span>label<span style="color: #060; font-weight: bold;">&gt;</span>
<span style="color: #060; font-weight: bold;">&lt;</span>input type<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;text&quot;</span> id<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;State&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #060; font-weight: bold;">&lt;</span>label <span style="color: #909; font-weight: bold;">for</span><span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Zip&quot;</span><span style="color: #060; font-weight: bold;">&gt;</span>Zip<span style="color: #060; font-weight: bold;">:&lt;/</span>label<span style="color: #060; font-weight: bold;">&gt;</span>
<span style="color: #060; font-weight: bold;">&lt;</span>input type<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;text&quot;</span> id<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Zip&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span>
&nbsp;
<span style="color: #060; font-weight: bold;">&lt;</span>input type<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;button&quot;</span> id<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Save&quot;</span> value<span style="color: #060; font-weight: bold;">=</span><span style="color: #c00;">&quot;Save&quot;</span> <span style="color: #060; font-weight: bold;">/&gt;</span></pre></div></div>

<p>Note that the input elements have IDs matching the corresponding Person property. This will help us implement an improvement to our client-side code later on.</p>
<h3>One way <em>not</em> to do it</h3>
<p>Now that we’ve had a look at the front and back ends, it’s time to connect them together with a web service. One unfortunate anti-pattern that often emerges in this situation is a service method with too many parameters:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>WebMethod<span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> AddPerson<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> FirstName, <span style="color: #FF0000;">string</span> LastName, 
                      <span style="color: #FF0000;">string</span> Address, <span style="color: #FF0000;">string</span> City,
                      <span style="color: #FF0000;">string</span> State, <span style="color: #FF0000;">string</span> Zip<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  Person newPerson <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Person<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
  newPerson.<span style="color: #0000FF;">FirstName</span> <span style="color: #008000;">=</span> FirstName<span style="color: #008000;">;</span>
  newPerson.<span style="color: #0000FF;">LastName</span> <span style="color: #008000;">=</span> LastName<span style="color: #008000;">;</span>
  newPerson.<span style="color: #0000FF;">Address</span> <span style="color: #008000;">=</span> Address<span style="color: #008000;">;</span>
  newPerson.<span style="color: #0000FF;">City</span> <span style="color: #008000;">=</span> City<span style="color: #008000;">;</span>
  newPerson.<span style="color: #0000FF;">State</span> <span style="color: #008000;">=</span> State<span style="color: #008000;">;</span>
  newPerson.<span style="color: #0000FF;">Zip</span> <span style="color: #008000;">=</span> Zip<span style="color: #008000;">;</span>
&nbsp;
  newPerson.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Not only do we have to manually keep that method’s parameter list in sync with the Person class, but we also have to maintain the pointless object initialization code.</p>
<p>Calling the service on the client-side is just as messy too:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
  contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json; charset=utf-8&quot;</span><span style="color: #339933;">,</span>
  url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;PersonService.asmx/AddPerson&quot;</span><span style="color: #339933;">,</span>
  data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;{'FirstName':'&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#FirstName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;', &quot;</span>
       <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'LastName':'&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#LastName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;',&quot;</span>
       <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'Address':'&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#Address&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;',&quot;</span>
       <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'City':'&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#City&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;',&quot;</span>
       <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'State':'&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#State&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;',&quot;</span>
       <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'Zip':'&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#Zip&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'}&quot;</span><span style="color: #339933;">,</span>
  dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>As <em>ugly</em> as it is, that <strong>will</strong> work and be much faster than anything we could possibly implement in an UpdatePanel. <strong>It would also be a nightmare to maintain</strong>.</p>
<p>Let’s continue improving this until it’s something we can be proud of.</p>
<h3>Things can only get better</h3>
<p>A good first improvement is to refactor the web service to get rid of the parameter list and redundant object initialization.</p>
<p>Most examples (including my own) never go beyond passing a string, integer, or maybe an array, but that only scratches the surface of what’s possible. An underutilized feature of ASP.NET AJAX “ScriptService” methods is that <strong>they can accept complex types as parameters</strong> and parse those parameters from JSON.</p>
<p>Leveraging this, we can dramatically simplify the web service:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>WebMethod<span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> AddPerson<span style="color: #000000;">&#40;</span>Person NewPerson<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
  NewPerson.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Unfortunately, calling this method on the client-side is just as messy as ever:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
  contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json; charset=utf-8&quot;</span><span style="color: #339933;">,</span>
  url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;PersonService.asmx/AddPerson&quot;</span><span style="color: #339933;">,</span>
  data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;{'NewPerson': {'FirstName':'&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#FirstName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;',&quot;</span>
                     <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'LastName':'&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#LastName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;',&quot;</span>
                     <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'Address':'&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#Address&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;',&quot;</span>
                     <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'City':'&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#City&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;',&quot;</span>
                     <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'State':'&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#State&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;',&quot;</span>
                     <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'Zip':'&quot;</span> <span style="color: #339933;">+</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#Zip&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'}}&quot;</span><span style="color: #339933;">,</span>
  dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That’s about the same as before. However, instead of sending a flat group of input field values, now we’re sending a JSON object corresponding to the Person class.</p>
<p>In other words, that declarative JSON data string is equivalent to this JavaScript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> NewPerson <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Object<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
NewPerson.<span style="color: #660066;">FirstName</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#FirstName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">LastName</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#LastName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">Address</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#Address&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">City</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#City&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">State</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#State&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">Zip</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#Zip&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>ASP.NET AJAX seamlessly translates the JSON string into a new instance of our Person class and passes that object into the service method. It works exactly as you’d expect, which is almost too good to be true!</p>
<h3>Cleaning up the client-side</h3>
<p>The best way to improve the client-side situation is to abandon our manual JSON serialization in the $.ajax() call. It works well enough for a couple parameters, but has devolved into <a href="http://en.wikipedia.org/wiki/Big_ball_of_mud" rel="nofollow" target="_blank">a ball of mud</a> as the parameter count increased.</p>
<p>Douglas Crockford’s <a href="http://www.json.org/js.html" target="_blank">json2.js</a> contains a <strong>stringify</strong> function which is exactly what we need. Stringify() accepts a JSON object and returns the same type of string that we’re manually concatenating together right now.</p>
<p>Using json2.js, our previous client-side code can be refactored to this:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Initialize the object, before adding data to it.</span>
<span style="color: #003366; font-weight: bold;">var</span> NewPerson <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Object<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
NewPerson.<span style="color: #660066;">FirstName</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#FirstName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">LastName</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#LastName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">Address</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#Address&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">City</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#City&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">State</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#State&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">Zip</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#Zip&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
  contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json; charset=utf-8&quot;</span><span style="color: #339933;">,</span>
  url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;PersonService.asmx/AddPerson&quot;</span><span style="color: #339933;">,</span>
  data<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;{'NewPerson':&quot;</span> <span style="color: #339933;">+</span> JSON.<span style="color: #660066;">stringify</span><span style="color: #009900;">&#40;</span>NewPerson<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;}&quot;</span><span style="color: #339933;">,</span>
  dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>It’s still a fair amount of code, but <strong>it’s much cleaner</strong>. If you dropped this in my lap and asked me to maintain it, we wouldn’t have a problem.</p>
<h3>Using a data transfer object</h3>
<p>Adding json2.js and its stringify functionality made our code significantly more readable, but <strong>we can do better</strong>. There’s still a bit of manual JSON string building in the $.ajax() call, which would be nice to avoid.</p>
<p>Since we already have JSON.stringify() at our disposal, we can build and stringify a JSON object to represent the entire request&#8217;s data instead of just the form data:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Initialize the object, before adding data to it.</span>
<span style="color: #006600; font-style: italic;">//  { } is declarative shorthand for new Object().</span>
<span style="color: #003366; font-weight: bold;">var</span> NewPerson <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
NewPerson.<span style="color: #660066;">FirstName</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#FirstName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">LastName</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#LastName&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">Address</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#Address&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">City</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#City&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">State</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#State&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
NewPerson.<span style="color: #660066;">Zip</span> <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#Zip&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Create a data transfer object (DTO) with the proper structure.</span>
<span style="color: #003366; font-weight: bold;">var</span> DTO <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'NewPerson'</span> <span style="color: #339933;">:</span> NewPerson <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
  contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json; charset=utf-8&quot;</span><span style="color: #339933;">,</span>
  url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;PersonService.asmx/AddPerson&quot;</span><span style="color: #339933;">,</span>
  data<span style="color: #339933;">:</span> JSON.<span style="color: #660066;">stringify</span><span style="color: #009900;">&#40;</span>DTO<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>By creating a data transfer object (often referred to as a DTO), we’ve <strong>completely eliminated all manual JSON string building</strong>.</p>
<p>Even though it’s a small change, it feels quite a bit cleaner doesn’t it?</p>
<h3>Bonus: jQuery makes everything better</h3>
<p>Using the DTO makes sending the form data clean, but we’re still stuck with <strong>the unnecessary chore of maintaining the NewPerson initialization block</strong>. jQuery is perfectly suited to solving this problem:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Initialize the object, before adding data to it.</span>
<span style="color: #006600; font-style: italic;">//  { } is declarative shorthand for new Object().</span>
<span style="color: #003366; font-weight: bold;">var</span> NewPerson <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Iterate over all the text fields and build an</span>
<span style="color: #006600; font-style: italic;">//  object with their values as named properties.</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">':text'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Ex: NewPerson['FirstName'] = $('#FirstName').val();</span>
  NewPerson<span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Create a data transfer object (DTO) with the proper structure.</span>
<span style="color: #003366; font-weight: bold;">var</span> DTO <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">'NewPerson'</span> <span style="color: #339933;">:</span> NewPerson <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;POST&quot;</span><span style="color: #339933;">,</span>
  contentType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;application/json; charset=utf-8&quot;</span><span style="color: #339933;">,</span>
  url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;PersonService.asmx/AddPerson&quot;</span><span style="color: #339933;">,</span>
  data<span style="color: #339933;">:</span> JSON.<span style="color: #660066;">stringify</span><span style="color: #009900;">&#40;</span>DTO<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  dataType<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;json&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Using <a href="http://docs.jquery.com/Core/each" target="_blank">jQuery.each()</a> to iterate over the fields and build our client-side object is a nice improvement. Even in this simple example, it cuts down on the amount of JavaScript we have to write and maintain. In real-world scenarios where your objects have dozens of properties, this will save you a lot of time (and typos).</p>
<p>More important than saving a few keystrokes, <strong>we’ve got one less place to worry about updating if the Person class changes in the future</strong>. We can modify the Person class, update the entry form accordingly, and this will continue working.</p>
<h3>Conclusion</h3>
<p>We have <em>solidly</em> accomplished the goal of refactoring this until it’s something we can be proud of. There’s always room for improvement, but this will serve as a great start for writing robust, maintainable client-side service calls.</p>
<p><strong>Death by a thousand dependencies</strong>: When I first started experimenting with this <em>stringified DTO pattern</em>, I was reluctant to take on the json2.js dependency. However, it’s tiny when minified, has no dependencies of its own, and is ideal for rolling into another combined script. Its dependable functionality is well worth a few kilobytes.</p>
<p>A great thing about committing to the JSON.stringify usage is that <a href="http://blog.mozilla.com/webdev/2009/02/12/native-json-in-firefox-31/" target="_blank">web browsers are beginning to natively support it</a>. So, at some point in the future, you’ll actually be able to drop the json2.js dependency and this method will still work (faster).</p>
<p><strong>DTOs</strong>: If your server-side situation is more complex than this example (and it probably is), don’t be afraid to use a throw-away DTO class as the service method parameter.</p>
<p>For example, our Person class could also have been a PersonDTO class, specifically intended to take these form submissions and merge them into a more complicated domain.</p>
<h3>Source</h3>
<p><a href="http://encosia.com/source/jQuery-DTO.zip"><img src="http://encosia.com/blog/wp-content/uploads/2009/04/jquery-dto-download-bar.png" alt="jQuery DTO source download" title="jQuery DTO source download" width="492" height="46" /></a></p>
<p><p>###</p>

<p>Originally posted at <a href="http://encosia.com">Encosia</a>.  If you're reading this elsewhere, come on over and see the original.</p><br/><br/><a href="http://encosia.com/2009/04/07/using-complex-types-to-make-calling-services-less-complex/">Using complex types to make calling services less&#8230; complex</a></p>
]]></content:encoded>
			<wfw:commentRss>http://encosia.com/2009/04/07/using-complex-types-to-make-calling-services-less-complex/feed/</wfw:commentRss>
		<slash:comments>59</slash:comments>
		</item>
	</channel>
</rss>
