<?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>Global Nerdy &#187; Ajax</title>
	<atom:link href="http://www.globalnerdy.com/tag/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.globalnerdy.com</link>
	<description>Tech Evangelist Joey deVilla on software development, tech news and other nerdy stuff</description>
	<lastBuildDate>Thu, 19 Nov 2009 02:16:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Taking JavaScript Performance to the Extreme with Thomas Fuchs</title>
		<link>http://www.globalnerdy.com/2009/11/09/taking-javascript-performance-to-the-extreme-with-thomas-fuchs/</link>
		<comments>http://www.globalnerdy.com/2009/11/09/taking-javascript-performance-to-the-extreme-with-thomas-fuchs/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 16:34:30 +0000</pubDate>
		<dc:creator>Joey deVilla</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[web applications]]></category>

		<guid isPermaLink="false">http://www.globalnerdy.com/?p=4662</guid>
		<description><![CDATA[&#34;Extreme JavaScript Performance&#34; (from JSConf.eu, November 7)

Take a look at the slides from Extreme JavaScript Performance, a presentation by Thomas Fuchs, creator of the script.aculo.us JavaScript library, collaborator on the book Agile Web Development with Rails and one of the people behind FailCamp. He gave the presentation last week at JSConf.eu in Berlin.
In the presentation, [...]]]></description>
			<content:encoded><![CDATA[<p></p><h3>&quot;Extreme JavaScript Performance&quot; (from JSConf.eu, November 7)</h3>
<p align="center"><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=2449719&amp;stripped_title=extreme-javascript-performance" /><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=2449719&amp;stripped_title=extreme-javascript-performance" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object></p>
<p><img style="border-right-width: 0px; margin: 0px 0px 10px 15px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="thomas fuchs" border="0" alt="thomas fuchs" align="right" src="http://www.globalnerdy.com/wordpress/wp-content/uploads/2009/11/thomasfuchs.jpg" width="200" height="199" /><strong>Take a look at the slides from <em><a href="http://www.slideshare.net/madrobby/extreme-javascript-performance">Extreme JavaScript Performance</a></em>,</strong> a presentation by <a href="http://mir.aculo.us/"><strong>Thomas Fuchs</strong></a>, creator of the <a href="http://script.aculo.us/"><strong>script.aculo.us</strong></a> JavaScript library, collaborator on the book <a href="http://pragprog.com/titles/rails2/agile-web-development-with-rails"><em>Agile Web Development with Rails</em></a> and one of the people behind <a href="http://failcamp.org/">FailCamp</a>. He gave the presentation last week at JSConf.eu in Berlin.</p>
<p>In the presentation, Thomas looked at six simple things you can do to boost the performance of your JavaScript:</p>
<ul>
<li>Use inline functions instead of function calls. </li>
<li>Embrace the language – using the language’s conventions yields unexpectedly faster code. Instantiate arrays using <code>var myArray = []</code> instead of <code>var a = new Array</code>, and instantiate objects using <code>var myObject = {}</code> instead of <code>var o = new Object</code>. </li>
<li>Unroll your loops! (A trick so old that we covered it when I was in school!) </li>
<li>Cache globals. If you’re going to access a global object, store a local reference and use that instead. </li>
<li>Tune your boolean expressions: in logical “AND” (<code>&amp;&amp;</code>) operations, make the operand most likely to be false the first one. </li>
<li>Watch out for slow constructs such as with blocks, try/catch and features that JIT compilers don’t support well. </li>
</ul>
<p>The presentation includes benchmarks for the four most common JavaScript engines:</p>
<ul>
<li>SpiderMonkey (Firefox 3.5) </li>
<li>JavaScript Core (Safari 4) </li>
<li>JScript (Internet Explorer 8) </li>
<li>V8 (Google Chrome) </li>
</ul>
<p>And yes, he does warn you – at least twice – of the dangers of premature optimization.</p>
<h3>JavaScript Performance Rocks</h3>
<p><a href="http://javascriptrocks.com/performance/"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="JavaScript performance rocks" border="0" alt="JavaScript performance rocks" src="http://www.globalnerdy.com/wordpress/wp-content/uploads/2009/11/JavaScriptperformancerocks.jpg" width="600" height="216" /></a> </p>
<p>If you liked <em>Extreme JavaScript Performance</em>, you’ll love the ebook Thomas co-authored with <a href="http://www.slash7.com/">Amy Hoy</a>, <strong><em><a href="http://javascriptrocks.com/performance/">JavaScript Performance Rocks!</a></em></strong> Actually, it’s more than just a book – it’s <em>four</em> books and a profiling tool:</p>
<ul>
<li><strong>Book 1: Understanding and Measuring Performance (or: “Dude, Where’s My Performance?”)</strong> &#8211; “In which our brave hero or heroine (that&#8217;s you!) apprentices to the cryptic-but-charming Master (that&#8217;s us) and learns how to get into the enemy&#8217;s head—the better to eat it alive, my dear.” </li>
<li><strong>Book 2: Loadtime (or: “The Land of Unicorn Tears”)</strong> &#8211; “Loadtime is a sad time, a time of of enormous, slow-loading assets; of maxed-out request queues; of bloated, waddling DOMs. Of limp white screens. Most of the world&#8217;s worst web performance woes? They live and breed in Loadtime. That&#8217;s why it&#8217;s the Land of Unicorn Tears, because unicorns hate slow web apps just as much as the rest of us. And they have magical horns. So there.“ </li>
<li><strong>Book 3: Runtime (or: “’Cuz Tuning Loops is Hardcore”)</strong> &#8211; “The vast majority of the problems that the vast majority of apps will have can be solved with loadtime fixes of various stripes. But just in case you&#8217;re unique, and special, and have particularly intractable issues—or are just a glutton for punishment—we have written a third booklet, all about speeding up code when it runs.” </li>
<li><strong>Book 4: Interface Coping Strategies (or: “If You Can’t Fix It, Fake It”)</strong> – “Come across a performance problem that you really can&#8217;t fix? Long-running calculations? Slow server you can&#8217;t tune up? <em>If you can&#8217;t make it, fake it.</em> You can make your app <em>feel</em> faster to your customers, even if you can&#8217;t fix the underlying problem. And, let&#8217;s face it, that&#8217;s what your customers care about.” </li>
<li><strong>The DOM Monster profiling tool.</strong> </li>
</ul>
<p><strong><em><a href="http://javascriptrocks.com/performance/">JavaScript Performance Rocks!</a></em> isn’t your ordinary ebook,</strong> with material laid out for a dead-tree book simply cast in PDF form. It was designed from the ground up for onscreen reading, written in an entertaining way to keep you amused and your mind ready to learn, and written in a fun, irreverent way so that you don’t zone out. I know Thomas and Amy personally and have seen them teach; trust me – you want to learn from them.</p>
<p><strong><em><a href="http://javascriptrocks.com/performance/">JavaScript Performance Rocks!</a></em> usually sells for US$49, but there’s a special deal right now – the first 500 books are selling for 10 dollars less &#8212; US$39.</strong> You’ve got two good reason to buy immediately: first, there’s this $10 discount, and second, the US/Canada exchange rate’s pretty good right now (as I write this, the PayPal exchange rate is CAD$1 = US$0.92).</p>
<p>I’ve already ordered my copy.</p>
<p class="alert"><a href="http://blogs.msdn.com/cdndevs/archive/2009/11/09/taking-javascript-performance-to-the-extreme-with-thomas-fuchs.aspx">This article also appears in <em>Canadian Developer Connection</em>.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.globalnerdy.com/2009/11/09/taking-javascript-performance-to-the-extreme-with-thomas-fuchs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>I&#8217;m in Calgary Next Week</title>
		<link>http://www.globalnerdy.com/2008/12/04/im-in-calgary-next-week/</link>
		<comments>http://www.globalnerdy.com/2008/12/04/im-in-calgary-next-week/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 14:58:59 +0000</pubDate>
		<dc:creator>Joey deVilla</dc:creator>
				<category><![CDATA[Meetups]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[What Joey Did]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Calgary]]></category>
		<category><![CDATA[conferences]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Tech Days]]></category>

		<guid isPermaLink="false">http://www.globalnerdy.com/2008/12/04/im-in-calgary-next-week/</guid>
		<description><![CDATA[ 
 
I’ll be in Calgary from Monday to Friday next week, catching up with my friend and co-worker John Bristowe (he’s Microsoft’s Developer Evangelist for Western Canada) and speaking at the Tech Days conference.
If you use (or are thinking of using) The Empire’s technologies, Tech Days is a pretty good place to get immersed. [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="downtown_calgary" border="0" alt="downtown_calgary" src="http://www.globalnerdy.com/wordpress/wp-content/uploads/2008/12/downtown-calgary.jpg" width="600" height="400" /> </p>
<p><a href="http://www.microsoft.com/canada/techdays/sessions.aspx?city=Calgary"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="tech_days_calgary" border="0" alt="tech_days_calgary" align="right" src="http://www.globalnerdy.com/wordpress/wp-content/uploads/2008/12/tech-days-calgary.jpg" width="250" height="261" /></a> </p>
<p>I’ll be in <a href="http://en.wikipedia.org/wiki/Calgary,_Alberta">Calgary</a> from Monday to Friday next week, catching up with my friend and co-worker <strong>John Bristowe</strong> (he’s Microsoft’s Developer Evangelist for Western Canada) and speaking at the <strong><a href="http://www.microsoft.com/canada/techdays/default.aspx">Tech Days</a></strong> conference.</p>
<p>If you use (or are thinking of using) The Empire’s technologies, Tech Days is a pretty good place to get immersed. It’s a conference focused on learning about Microsoft tech on its target platforms – PC, web and phone – both current and upcoming. It’s also a chance for Microsoft developers to get together and network, and you leave the conference with a nice package of free stuff, including a full version of <a href="http://msdn.microsoft.com/en-us/vs2008/products/bb894671.aspx">Visual Studio 2008 Professional Edition</a>. (And just between you and me, if your company’s paying for it, Tech Days is also a good excuse to get a couple of paid days out of the office.)</p>
<p>In addition to the conference notes and reportage that you’ve come to expect from <em>Global Nerdy </em>and the accordion playing you’ve come to expect from me, I will be contributing in another way: I’m delivering the <strong><em>A Deep Dive into the ASP.NET Ajax Extensions</em></strong> presentation (it’s part of the web development track and taking place on Wednesday, December 10th at 1:00 p.m.. Here’s the abstract for the presentation:</p>
<blockquote><p>The ASP.NET AJAX Extensions are the server half of ASP.NET AJAX. Aside from adding controls such as ScriptManager and UpdatePanel to the platform, they extend the ASMX model to support client-side callbacks and JSON serialization. In this session, we&#8217;ll explore ASP.NET AJAX on the server &#8211; both inside and out &#8211; in order to provide you with the knowledge you will need to exploit it to its fullest.</p>
</blockquote>
<p>(If I had more time, I think I’d write my own abstract.)</p>
<p>I looked at the time slot I was given and went “uh-oh”. It’s one p.m., right after lunch, which is what people used to call the <em>sexta hora</em> in Latin. That means “sixth hour” and refers to the sixth hour of being awake, which is when people start to get a little bit sleepy. That’s where the word <em>siesta</em> comes from – it’s a bastardization of <em>sexta hora</em>. I’m going to have to make sure that I keep things interesting – I welcome that challenge.</p>
<p>See you in Calgary!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.globalnerdy.com/2008/12/04/im-in-calgary-next-week/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A Fix for the Error in Hour 9 of &#8220;Teach Yourself ASP.NET Ajax in 24 Hours&#8221; / Client-Side Error Handling in ASP.NET Ajax in .NET 3.5</title>
		<link>http://www.globalnerdy.com/2008/12/03/a-fix-for-the-error-in-hour-9-of-teach-yourself-aspnet-ajax-in-24-hours-client-side-error-handling-in-aspnet-ajax-in-net-35/</link>
		<comments>http://www.globalnerdy.com/2008/12/03/a-fix-for-the-error-in-hour-9-of-teach-yourself-aspnet-ajax-in-24-hours-client-side-error-handling-in-aspnet-ajax-in-net-35/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 19:40:55 +0000</pubDate>
		<dc:creator>Joey deVilla</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET 3.5]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[errata]]></category>
		<category><![CDATA[error handling]]></category>
		<category><![CDATA[exception handling]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[PageRequestManager]]></category>
		<category><![CDATA[ScriptManager]]></category>

		<guid isPermaLink="false">http://www.globalnerdy.com/2008/12/03/a-fix-for-the-error-in-hour-9-of-teach-yourself-aspnet-ajax-in-24-hours-client-side-error-handling-in-aspnet-ajax-in-net-35/</guid>
		<description><![CDATA[While following the exercises in the book Teach Yourself ASP.NET Ajax in 24 Hours – one of the few books I’ve been able to find on Ajax for ASP.NET 3.5 – I found an error in the “Hour 9” chapter in the example that covers client-side error-handling (it starts on page 137). I’ve reported this [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://www.amazon.com/Sams-Teach-Yourself-ASP-NET-Hours/dp/0672329670"><img style="border-right-width: 0px; margin: 0px 0px 10px 10px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Cover of &quot;Teach Yourself ASP.NET Ajax in 24 Hours&quot;" border="0" alt="Cover of &quot;Teach Yourself ASP.NET Ajax in 24 Hours&quot;" align="right" src="http://www.globalnerdy.com/wordpress/wp-content/uploads/2008/12/teach-yourself-aspnet-ajax-in-24-hours.jpg" width="185" height="240" /></a>While following the exercises in the book <em><a href="http://www.amazon.com/Sams-Teach-Yourself-ASP-NET-Hours/dp/0672329670"><strong>Teach Yourself ASP.NET Ajax in 24 Hours</strong></a></em> – one of the few books I’ve been able to find on Ajax for ASP.NET 3.5 – I found an error in the “Hour 9” chapter in the example that covers client-side error-handling (it starts on page 137). I’ve reported this error to the publisher and with any luck, they’ll post a corrected version on their support web page for the book.</p>
<p>I’ve done some searching and haven’t found anything covering this error so I thought I’d cover it here. Better still, I’ll also cover the fix, which turns out to be quite simple. If you’ve been trying out the code in the book and wondering why it doesn’t work, relax: at least in this case, it’s not your fault.</p>
<p>In the course of covering the error and how to fix it, I’ll also talk about how ASP.NET handles exceptions raised by asynchronous postbacks and how you can make use of it to make better user interfaces. Even if you don’t have a copy of <em>Teach Yourself ASP.NET Ajax in 24 Hours,</em> you should find this article an interesting introduction to client-side error handling in ASP.NET Ajax.</p>
<h3>Unhandled Exceptions and Asynchronous Postbacks</h3>
<p>In ASP.NET Ajax, if an exception is raised during an asynchronous postback and isn’t handled on the server side – that is, in the code-behind – it gets passed along to the client side. What happens on the client side depends on which version of ASP.NET you’re using:</p>
<ul>
<li><strong>In ASP.NET Ajax 1.0,</strong> the server-side exception object is serialized into <a href="http://www.json.org/">JSON</a>. The JSON is sent to the client, which displays the exception’s message property in an alert box. </li>
<li><strong>In ASP.NET Ajax for .NET 3.5,</strong> the server-side exception is still serialized into JSON and the JSON is still sent to the client. However, instead of displaying the exception’s message property in an alert box – a presumptuous design decision, if you want my opinion – the client throws the exception, which gives you the opportunity to handle it on the client side as you please. </li>
</ul>
<p>(In this article, I’ll stick to covering ASP.NET Ajax for .NET 3.5.)</p>
<p>This is quite different from most other web application frameworks, where an exception raised as the result of an <a href="http://www.w3.org/TR/XMLHttpRequest/">XMLHttpRequest</a> call to the server results in some kind of “error” page from the server (or a blank page, if you’re suppressing error reporting). </p>
<p>To illustrate this, let’s put together a simple ASP.NET Ajax application. It’s a single page with a single button, that if clicked, throws an exception.</p>
<p>Here’s the code for the page layout. It’s pretty straightforward:</p>
<p><strong>Listing 1: <code>Default.aspx</code> – Layout for the page of our simple ASP.NET Ajax application<em>.</em></strong></p>
<p> <code>
<pre>&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot;
CodeBehind=&quot;Default.aspx.cs&quot; Inherits=&quot;WebApplication1._Default&quot; %&gt;

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;
&lt;head runat=&quot;server&quot;&gt;
    &lt;title&gt;Error Handling Demo 1&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;

        &lt;div&gt;
            &lt;asp:ScriptManager ID=&quot;ScriptManager1&quot; runat=&quot;server&quot; /&gt;
            &lt;asp:UpdatePanel runat=&quot;server&quot; ID=&quot;UpdatePanel1&quot;&gt;
                &lt;ContentTemplate&gt;
                    &lt;asp:Button runat=&quot;server&quot; ID=&quot;Button1&quot;
                    Text=&quot;Click Me&quot; OnClick=&quot;Button1_OnClick&quot; /&gt;
                &lt;/ContentTemplate&gt;
            &lt;/asp:UpdatePanel&gt;
        &lt;/div&gt;

    &lt;/form&gt;
&lt;/body&gt;

&lt;/html&gt;</pre>
<p></code></p>
<p>Some notes about the code:</p>
<ul>
<li>The <code>ScriptManager</code> control at the top of the form enables Ajax by ensuring that the JavaScript needed to support ASP.NET Ajax on the client side is downloaded to the browser. </li>
<li>The <code>UpdatePanel</code> control determines the controls that trigger asynchronous postbacks and defines the region of the page that can be updated via Ajax. </li>
<li><code>Button1</code> is the button control that we want to throw an exception when clicked. We’ll set it to call the <code>Button1_OnClick</code> method, which will contain the exception-throwing code. </li>
</ul>
<p>The code-behind is very simple. In it, we define a single method: the event handler <code>Button1_OnClick</code>, which is called in response when the user clicks <code>Button1</code>. All we want it to do is throw an exception that uniquely identifies itself:</p>
<p><strong>Listing 2: <code>Default.aspx.cs</code> – Code-behind for the page of our very simple example app<em>.</em></strong></p>
<p><code></p>
<pre>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Button1_OnClick(object sender, EventArgs e)
        {
            throw new Exception(&quot;Click!&quot;);
        }
    }
}</pre>
<p></code></p>
<h4>Running with Debugging vs. Running Without Debugging</h4>
<p>Listing 1 and 2 give us enough to make our simple app work. It’s time to take it for a spin.</p>
<p>Here’s something that doesn’t get covered in <em>Teach Yourself ASP.NET Ajax in 24 Hours: </em>what happens when you try to run this app <em>with</em> debugging (starting it by hitting F5 in Visual Studio or “Start Debugging” under the “Debug” menu)? </p>
<p>Here’s a screenshot of what happened for me: <img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="simple_app_with_debugging" border="0" alt="simple_app_with_debugging" src="http://www.globalnerdy.com/wordpress/wp-content/uploads/2008/12/simple-app-with-debugging.jpg" width="567" height="417" /> </p>
<p>With debugging on, the unhandled exception thrown in <code>Button1_OnClick</code> is caught by the debugger. Normally, this sort of error-catching behaviour is welcome, but in this particular case, it gets in the way of what we’re trying to achieve: having an exception on the server side and passing it along to the user’s browser to handle.</p>
<p>If we run the same app without debugging, we get the effect we want: the exception is raised on the server side, but the server-side part of the application doesn’t halt with an error message. Instead, the client shows the error message.</p>
<p>Here’s a screenshot. Note that the error message includes the string “Click!”, which is the argument in the throw statement the <code>Button1_OnClick</code> event handler. Thanks to this, we can be pretty certain that the error message is the result of our deliberately-thrown exception:</p>
<p><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://www.globalnerdy.com/wordpress/wp-content/uploads/2008/12/image.png" width="502" height="327" /></p>
<p>Now that we have the exception that we threw on the server side being handled on the client side, let’s do something with it.&#160; </p>
</p>
<h3>Handling Exceptions Passed from the Server on the Client Side</h3>
<p>Let’s do something simple – let’s catch the exception caused by the button click, and instead of having a JavaScript error box pop up, let’s make a couple of changes to the button:</p>
<ul>
<li>Change its text to “This button has been disabled for your safety.” </li>
<li>Disable it. </li>
</ul>
<p>To handle exceptions on the client side, we need to write some client-side JavaScript. Luckily, this is made simple by the number of handy utility classes defined in the scripts downloaded to the client by the <code>ScriptManager</code> component. In this case, we’re going to make use of the <code><a href="http://msdn.microsoft.com/en-us/library/bb311028.aspx">Sys.Webforms.PageRequestManager</a></code> class to deal with the exception because it provides us with the following:</p>
<ul>
<li>The <code><a href="http://msdn.microsoft.com/en-us/library/bb383810.aspx">endRequest</a></code> event, which is raised after an asynchronous postback has completed and control is returned to the browser. </li>
<li>The <code>add_endRequest</code> method, which specifies a method to call when the <code>endRequest</code> event is raised. </li>
</ul>
<p>Here’s the JavaScript, which we’ll put in a file called <code>ErrorHandler.js</code>:</p>
<p><strong>Listing 3: <code>ErrorHandler.js</code> &#8212; Client-side error handler for our very simple example app<em>.</em></strong></p>
<p><code></p>
<pre>Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

function EndRequestHandler(sender, args)
{
    if (args.get_error() != undefined) {
        $get('Button1').value = &quot;This button has been disabled for your safety.&quot;;
        $get('Button1').disabled = true;
        args.set_errorHandled(true);
    }
}</pre>
<p></code></p>
<p>The script performs the following:</p>
<ul>
<li>It registers the method <code>EndRequestHandler</code> as the method to call whenever the <code>endRequest</code> event is raised. </li>
<li>It defined the method <code>EndRequestHandler</code>, which does the following:
<ul>
<li>If an exception did occur during the asynchronous callback:&quot;
<ul>
<li>The button’s text is changed </li>
<li>The button is disabled </li>
<li>The error is reported as handled, which allows the application to continue </li>
</ul>
</li>
</ul>
</li>
</ul>
<p>Now that we have this client-side code, we need to get it to the client. We do this by using the <code>Scripts</code> section of the <code>ScriptManager</code> to send this file to the client. The listing below shows the updated layout code for our simple application. I’ve highlighted the change in the listing below:</p>
<p><strong>Listing 4: Revised <code>Default.aspx</code> – Layout for the page of our simple ASP.NET Ajax application<em>.</em></strong></p>
<p><code></p>
<pre>&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;Default.aspx.cs&quot; Inherits=&quot;WebApplication1._Default&quot; %&gt;

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;
&lt;head runat=&quot;server&quot;&gt;
    &lt;title&gt;Error Handling Demo 1&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;

        &lt;div&gt;
            <b>&lt;asp:ScriptManager ID=&quot;ScriptManager1&quot; runat=&quot;server&quot;&gt;
                &lt;Scripts&gt;
                    &lt;asp:ScriptReference Path=&quot;~/ErrorHandler.js&quot; /&gt;
                &lt;/Scripts&gt;
            &lt;/asp:ScriptManager&gt;</b>
            &lt;asp:UpdatePanel runat=&quot;server&quot; ID=&quot;UpdatePanel1&quot;&gt;
                &lt;ContentTemplate&gt;
                    &lt;asp:Button runat=&quot;server&quot; ID=&quot;Button1&quot;
                    Text=&quot;Click Me&quot; OnClick=&quot;Button1_OnClick&quot; /&gt;
                &lt;/ContentTemplate&gt;
            &lt;/asp:UpdatePanel&gt;
        &lt;/div&gt;

    &lt;/form&gt;
&lt;/body&gt;

&lt;/html&gt;</pre>
<p></code></p>
<p><strong></strong></p>
<p>The <code>Scripts</code> section of the <code>ScriptManager</code> lets us specify scripts to be sent to the client along with the page, with each script specified in a <code>ScriptReference</code> tag.</p>
<p>When we run the app (remember, <em>without </em>debugging on) with these changes and click the button, here’s what we get:</p>
<p><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Button with text &quot;This button has been disabled for your safety&quot;" border="0" alt="Button with text &quot;This button has been disabled for your safety&quot;" src="http://www.globalnerdy.com/wordpress/wp-content/uploads/2008/12/sample-app-revised-screenshot.gif" width="401" height="43" /> </p>
<p>In a later article, I’ll look at other ways of using client-side error handling in ASP.NET Ajax in .NET 3.5.</p>
<h3>The Error in <em>Teach Yourself ASP.NET Ajax in 24 Hours</em></h3>
<p>Here’s the page layout code for the error-handling example in <em>Teach Yourself ASP.NET Ajax in 24 Hours</em>. The code-behind for the page and the client-side JavaScript are fine, it’s this code that has the error. See if you can spot what’s amiss:</p>
<p><strong>Listing 5: <code>Default.aspx</code> &#8212; Page layout of client-side error-handling example in Hour 9 of <em>Teach Yourself ASP.NET Ajax in 24 Hours.</em></strong></p>
<p><code></p>
<pre>&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;Default.aspx.cs&quot; Inherits=&quot;WebApplication1._Default&quot; %&gt;

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;
&lt;head runat=&quot;server&quot;&gt;
    &lt;title&gt;&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
    &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;

        &lt;div&gt;
            &lt;asp:ScriptManager ID=&quot;ScriptManager1&quot; runat=&quot;server&quot; /&gt;
            &lt;asp:UpdatePanel runat=&quot;server&quot; ID=&quot;UpdatePanel1&quot;&gt;
                &lt;ContentTemplate&gt;
                    &lt;asp:Button runat=&quot;server&quot; ID=&quot;Button1&quot;
                    Text=&quot;Click Me&quot; OnClick=&quot;Button1_OnClick&quot; /&gt;
                &lt;/ContentTemplate&gt;
            &lt;/asp:UpdatePanel&gt;
        &lt;/div&gt;

        &lt;br /&gt;&lt;br /&gt;

        &lt;div id=&quot;Message&quot; style=&quot;visibility: hidden;&quot;&gt;
            &lt;asp:HyperLink ID=&quot;HyperLink1&quot; runat=&quot;server&quot;
                           Font-Bold=&quot;true&quot;
                           Text=&quot;Error Occurred...&quot;
                           Font-Italic=&quot;true&quot;
                           ForeColor=&quot;red&quot; &gt;
            &lt;/asp:HyperLink&gt;
        &lt;/div&gt;

    &lt;/form&gt;
&lt;/body&gt;

&lt;/html&gt;</pre>
<p></code></p>
<p>Just for kicks, here’s what happens when you click on the button in the app using the code straight from <em>Teach Yourself ASP.NET Ajax in 24 Hours</em>:</p>
<p><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="Screen capture of resulting error message from original &quot;Teach Yourself ASP.NET Ajax in 24 Hours&quot; application" border="0" alt="Screen capture of resulting error message from original &quot;Teach Yourself ASP.NET Ajax in 24 Hours&quot; application" src="http://www.globalnerdy.com/wordpress/wp-content/uploads/2008/12/screen-capture-1.gif" width="582" height="337" /></p>
<p>The mistake is simple: although there is some error-handling client-side JavaScript in the app, it’s not referenced in the <code>ScriptManager</code> tag, which means it’s not sent to the client. Without error-handling code on the client side, the exception is thrown, there’s nothing to catch it and the user is presented with the standard error dialog box.</p>
<p>The fix is equally simple: reference the script in the <code>ScriptManager</code> tag’s <code>Scripts</code> section:</p>
<p><code></p>
<pre>&lt;asp:ScriptManager ID=&quot;ScriptManager1&quot; runat=&quot;server&quot;&gt;
    &lt;Scripts&gt;
        &lt;asp:ScriptReference Path=&quot;~/ErrorHandlingScript.js&quot; /&gt;
    &lt;/Scripts&gt;
&lt;/asp:ScriptManager&gt;</pre>
<p></code></p>
<p>Once that’s done, the program works as promised.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.globalnerdy.com/2008/12/03/a-fix-for-the-error-in-hour-9-of-teach-yourself-aspnet-ajax-in-24-hours-client-side-error-handling-in-aspnet-ajax-in-net-35/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Websites You Shouldn&#8217;t Have Missed in April 2008</title>
		<link>http://www.globalnerdy.com/2008/04/29/websites-you-shouldnt-have-missed-in-april-2008/</link>
		<comments>http://www.globalnerdy.com/2008/04/29/websites-you-shouldnt-have-missed-in-april-2008/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 19:01:10 +0000</pubDate>
		<dc:creator>Joey deVilla</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[fonts]]></category>
		<category><![CDATA[freelance]]></category>
		<category><![CDATA[generators]]></category>
		<category><![CDATA[graphic design]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[icons]]></category>
		<category><![CDATA[Link-O-Rama]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://globalnerdy.com/?p=1641</guid>
		<description><![CDATA[Websites You Shouldn&#8217;t Have Missed in April 2008 is a collection of 52 links featuring graphic design tutorials, Ajax, CSS, tips for freelance workers, free fonts, icons and graphics, tools and generators, WordPress themes, typography sites and sites to inspire you. Well worth perusing.
]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://www.noupe.com/best-of/websites-you-shouldn%e2%80%99t-have-missed-in-april-2008.html"><strong>Websites You Shouldn&#8217;t Have Missed in April 2008</strong></a> is a collection of 52 links featuring graphic design tutorials, Ajax, CSS, tips for freelance workers, free fonts, icons and graphics, tools and generators, WordPress themes, typography sites and sites to inspire you. Well worth perusing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.globalnerdy.com/2008/04/29/websites-you-shouldnt-have-missed-in-april-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
