<?xml version="1.0" encoding="UTF-8"?>
<rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Helephant.com</title>
	<atom:link href="http://helephant.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://helephant.com</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Mon, 22 Jun 2009 21:36:03 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
		<title>Geeks are great but bet on the non-techies</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/lsgdaLbIEB0/</link>
		<comments>http://helephant.com/2009/06/geeks-are-great-but-bet-on-the-non-techies/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 21:32:18 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<category><![CDATA[facebook]]></category>

		<category><![CDATA[icq]]></category>

		<category><![CDATA[msn]]></category>

		<category><![CDATA[olddays]]></category>

		<category><![CDATA[ramblings]]></category>

		<category><![CDATA[socialnetwork]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1387</guid>
		<description><![CDATA[I was talking to a friend of mine who is boycotting Facebook. She was a little surprised that I have a Facebook profile. I told her that I have a Facebook profile because all my non-techie friends have one. It&#8217;s makes it easy to keep in touch with a heap of people that I quite [...]]]></description>
			<content:encoded><![CDATA[<p>I was talking to a friend of mine who is boycotting Facebook. She was a little surprised that I have a Facebook profile. I told her that I have a Facebook profile because all my non-techie friends have one. It&#8217;s makes it easy to keep in touch with a heap of people that I quite like to keep in touch with. It&#8217;s a place where people actually keep their current email up to date! </p>
<p>It reminded me of the old instant messenger days. I started off on ICQ when the web was still young and boy did I love it. Everyone I knew from Star Wars chat was on there. I had a ICQ number that was a low seven digit number! Sometimes when I was drifting off in maths class, I&#8217;d hear the little uh-oh message notification sound in my dreams.</p>
<p>Then MSN messenger came on the scene. I scoffed at Microsoft&#8217;s lame attempt to muscle in on instant messaging. I kept using my ICQ client and when that became too slow and bulky to be practical I switched to Trillian. </p>
<p>Then my friends at school started to get the internet at home and I started to want to talk to them. None of them used ICQ. They all used MSN. So I got a MSN account to talk to them and the people who I talked to on ICQ also started to switch to MSN. One day when I formatted my computer I just didn&#8217;t bother to load ICQ back on and that was the sad end to it. </p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/lsgdaLbIEB0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/06/geeks-are-great-but-bet-on-the-non-techies/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2009/06/geeks-are-great-but-bet-on-the-non-techies/</feedburner:origLink></item>
		<item>
		<title>Ada Lovelace day - Molly Holzschlag, Kathy Hassinger and my mum</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/JFCeuPSCpqg/</link>
		<comments>http://helephant.com/2009/03/ada-lovelace-day/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 22:58:47 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[Community]]></category>

		<category><![CDATA[AdaLovelaceDay09]]></category>

		<category><![CDATA[geek]]></category>

		<category><![CDATA[girly geeks]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1302</guid>
		<description><![CDATA[Today I&#8217;ve been really enjoying all the stories posted for Ada Lovelace day, a day where we&#8217;re encouraged to blog about remarkable women in IT. I thought it was a nice idea when my friend emailed me about it so I thought I&#8217;d pitch in and write about three geek women who inspire me. 
Web [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;ve been really enjoying all <a href="http://ada.pint.org.uk/map.html">the stories</a> posted for <a href="http://findingada.com/">Ada Lovelace day</a>, a day where we&#8217;re encouraged to blog about remarkable women in IT. I thought it was a nice idea when my friend emailed me about it so I thought I&#8217;d pitch in and write about three geek women who inspire me. </p>
<h2>Web development hero - Molly Holzschlag</h2>
<p>I&#8217;m a web developer. It was the internet that got me interested in computers beyond being a game machine. It was web development (and <a href="http://creatures.wikia.com/wiki/Creatures_Wiki_Homepage">Creatures</a>) that really made me want to be a programmer. I&#8217;ve been doing this for over ten years now and one woman who&#8217;s been a real hero of mine in the web development community is <a href="http://www.molly.com/">Molly Holzschlag</a>. </p>
<p>Molly has been part of the campaign to make the web a more open and interoperable place. She has <a href="http://www.molly.com/books.php">written books</a>, taught classes and given <a href="http://www.molly.com/2007/12/05/conversation-with-bill-gates-about-ie8-and-microsoft-transparency/">Bill Gates shit about the IE team going off the radar</a>. She has helped educate developers and been part of making web developers care about web standards, something that seemed like an impossible dream back in the late nineties browser wars. Now even Microsoft brags about <a href="http://blogs.msdn.com/ie/archive/2007/12/19/internet-explorer-8-and-acid2-a-milestone.aspx">improvements to standards compatibility</a> in their latest browser. Because of the work that she&#8217;s been part of, the web doesn&#8217;t belong to hyperglobal megacorp or the government (or Google - yet). It still belongs to us, anyone who hooks a box onto the network and spends some time communing with a text editor. </p>
<h2>A personal favourite geek girl - Kathy Hassinger</h2>
<p><a href="http://kathyhassinger.com/">Kathy&#8217;s</a> friend of mine who is a technical writer. Until recently she was working with developers to document software for scientists. How cool is that?</p>
<p>I wish I could write as engagingly and as amusingly as Kathy. Go read her <a href="http://rathersillyblog.blogspot.com/2009/03/ada-lovelace-day.html">Ada Lovelace</a> post. She managed to capture the essence of what&#8217;s important about the whole subject of women in IT with a story about Colonel Samantha Carter from StarGate and the one observation that she&#8217;s a powerful role model because the people on her team don&#8217;t treat her any differently because she&#8217;s a woman.</p>
<p>Geekdom needs people who can communicate and make people think about things as much as we need people who build things. Code isn&#8217;t enough by itself to make a product great, you also need to be able to connect with the people who use it, get them to trust you and then help them <a href="http://headrush.typepad.com/creating_passionate_users/2005/01/keeping_users_e.html">kick arse</a> with it. </p>
<p>Kathy&#8217;s not just a great writer. She&#8217;s a sweet, funny and vibrant person as well. She&#8217;s passing her geek heritage on to the next generation through her neice (who she dotes on, encourages and regularly takes to the local science centre). She&#8217;s one of those people who has always got something interesting to say about any topic. She is also unashamedly and openly a geek, something that inspires me to not try to hide who I am when I meet people who might not understand. </p>
<h2>Someone who made it possible for me - my Mum</h2>
<p>My mum&#8217;s an English language geek rather than a computer geek but it was her influence that made it possible for me to become a programmer. In our house there was never the idea that my sister and I had to be a certain way because we were girls. We were encouraged to read and to be imaginative and to build things. We played with lego as well as dolls, climbed trees, dug holes, made cubby houses. We were wrote stories and had a big box full of stuff to make things from. We were taught to question things (which drove my parents a little mad as we got older) and to think for ourselves. I was real lucky to get geek parents. :)</p>
<p>My mum loves to learn things and has three masters degrees in English. I can remember being about five or six and going with her to the University of Queensland when she was dropping in an assignment. I remember seeing the beautiful lawns and the huge sandstone buildings and telling myself that I was going to go there one day. I still had that image in my head when I was slogging through year 12. The story I told myself of the place created just so people could try new ideas and learn things was what made all that hard work seem worthwhile. </p>
<p>The biggest thing that I got from my mum that&#8217;s helped me be a programmer is my writing. Being able to communicate clearly and effectively is such a huge advantage to getting your ideas heard. Good ideas can&#8217;t change things if you can&#8217;t share them with other people. </p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/JFCeuPSCpqg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/03/ada-lovelace-day/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2009/03/ada-lovelace-day/</feedburner:origLink></item>
		<item>
		<title>To(): a handy way to convert strings to other types</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/4CSVcxDfCyE/</link>
		<comments>http://helephant.com/2009/02/to-a-handy-way-to-convert-strings-to-other-types/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 17:01:16 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[.NET]]></category>

		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[code]]></category>

		<category><![CDATA[extensionmethods]]></category>

		<category><![CDATA[generics]]></category>

		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1285</guid>
		<description><![CDATA[The int.parse() method is one I use a lot in ASP.NET so I wrote a handy extension method called To using generic return types and a little reflection that makes converting all these string values to another type incredibly simple.]]></description>
			<content:encoded><![CDATA[<p>A webpage is just a giant string. As fancy that the server side abstractions can get (particularly in the .NET world) all we&#8217;re ultimately doing is reading the string given to us by the browser request so we can build the right new string for it to display to the user. </p>
<p>.NET is a strongly typed world so this involves lots of parsing values from the strings. We need to parse strongly typed values from query strings, server controls, configuration files and a hundred other places where .NET meets the outside world. </p>
<p>So since I use int.parse() so much in ASP.NET so I wrote a <a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx">handy extension method</a> called To (perfect naming thanks Dan) using <a href="/2008/05/generic-method-return-types/">generic return types</a> and a little reflection that makes converting all these string values to another type incredibly simple:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">public</span> <span class="kw1">static</span> <span class="kw4">class</span> StringUtils</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// &lt;summary&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// This method will parse a value from a string.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// If the string is null or not the right format to parse a valid value,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// it will return the default value provided.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// &lt;/summary&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> T To<span class="sy0">&lt;</span>t<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="kw1">this</span> <span class="kw4">string</span> value, T defaultValue<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; where T<span class="sy0">:</span> <span class="kw4">struct</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; var type <span class="sy0">=</span> <span class="kw3">typeof</span><span class="br0">&#40;</span>T<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>value <span class="sy0">!=</span> <span class="kw1">null</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var parse <span class="sy0">=</span> type.<span class="me1">GetMethod</span><span class="br0">&#40;</span><span class="st0">&quot;TryParse&quot;</span>, <span class="kw3">new</span> Type<span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#123;</span> <span class="kw3">typeof</span><span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span>, type.<span class="me1">MakeByRefType</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var parameters <span class="sy0">=</span> <span class="kw3">new</span> <span class="kw4">object</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#123;</span> value, <span class="kw1">default</span><span class="br0">&#40;</span>T<span class="br0">&#41;</span> <span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw4">bool</span><span class="br0">&#41;</span>parse.<span class="me1">Invoke</span><span class="br0">&#40;</span><span class="kw1">null</span>, parameters<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span>T<span class="br0">&#41;</span>parameters<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> defaultValue;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// &lt;summary&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// This method will parse a value from a string.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// If the string is null or not the right format to parse a valid value,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// it will return the default value for the type.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// &lt;/summary&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> T To<span class="sy0">&lt;/</span>t<span class="sy0">&gt;&lt;</span>t<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="kw1">this</span> <span class="kw4">string</span> value<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; where T <span class="sy0">:</span> <span class="kw4">struct</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> value.<span class="me1">To</span><span class="sy0">&lt;/</span>t<span class="sy0">&gt;&lt;</span>t<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="kw1">default</span><span class="br0">&#40;</span>T<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>t<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>Now getting an int from the query string is only 10 extra characters to type:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1">var value <span class="sy0">=</span> Request.<span class="me1">QueryString</span><span class="br0">&#91;</span><span class="st0">&quot;value&quot;</span><span class="br0">&#93;</span>.<span class="me1">To</span><span class="sy0">&lt;</span><span class="kw4">int</span><span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span><span class="kw4">int</span><span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p><a href="/wp-content/uploads/2009/02/toextensionmethod.zip">Complete example</a></p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/4CSVcxDfCyE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/02/to-a-handy-way-to-convert-strings-to-other-types/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2009/02/to-a-handy-way-to-convert-strings-to-other-types/</feedburner:origLink></item>
		<item>
		<title>Improving the way ASP.NET handles 404 requests</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/EEz8GDSroow/</link>
		<comments>http://helephant.com/2009/02/improving-the-way-aspnet-handles-404-requests/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 13:51:43 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[404]]></category>

		<category><![CDATA[errorhandling]]></category>

		<category><![CDATA[http]]></category>

		<category><![CDATA[statuscodes]]></category>

		<category><![CDATA[userexperience]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1213</guid>
		<description><![CDATA[Sometimes things go wrong, information goes out of date, pages go missing. When these things happen it&#8217;s up to the humble 404 error page to let your users and the search engines know that things have changed. ASP.NET has a built in custom error pages feature to make it easy to set up your 404 [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes things go wrong, information goes out of date, pages go missing. When these things happen it&#8217;s up to the humble 404 error page to let your users and the search engines know that things have changed. ASP.NET has a built in <a href="http://www.codeproject.com/KB/aspnet/customerrorsinaspnet.aspx">custom error pages</a> feature to make it easy to set up your 404 page but here are a couple of tips to make the 404 experience a little better. </p>
<h2>Return the right status code</h2>
<p>By default the page handling a 404 error page <a href="http://searchengineland.com/url-rewriting-custom-error-pages-in-aspnet-20-12234">doesn&#8217;t return a 404 status code to the browser</a>. It displays the error message that you provided to the user but doesn&#8217;t have any extra information to flag the page as an error page. </p>
<p>This is called a <a href="http://googlewebmastercentral.blogspot.com/2008/08/farewell-to-soft-404s.html">soft 404</a>. Soft 404 pages aren&#8217;t as good as ones that return the 404 status code because returning the 404 status code lets anything accessing your file that the page is an error page rather than a real page of you site. This is mostly useful for search engines because then they know they should remove dead pages from their index so users won&#8217;t follow dead links into your site from results pages. </p>
<p>Pages that return 404 status codes are also useful for error detection because they&#8217;ll be recorded in your server logs so if you have unexpected 404 errors, they&#8217;ll be easy to find. Here&#8217;s an example of the 404 error report in <a href="https://www.google.com/webmasters/tools/">Google Webmaster tools</a>:<br />
<img src="/wp-content/uploads/2009/02/googlewebmaster.png" alt="Google webmaster tools has a nice report of any 404 links it found"/></p>
<p>Here&#8217;s how it looks if we use <a href="">Firebug</a> to spy on what&#8217;s happening when we load an invalid url into an ASP.NET application. It first shows a 302 redirect as the ASP.NET custom error handling code redirects from the original page to the custom 404 error handler. Then it shows a 200 ok code because the page is just a regular page and doesn&#8217;t know it should do any different:<br />
<img src="/wp-content/uploads/2009/02/soft404.png" alt="firebug shows a 302 redirect and then a 200 ok status code"/></p>
<p>This is very easy to fix. You just need to explicitly set the Response.StatusCode property to 404 in the 404 error page:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">protected</span> <span class="kw1">void</span> Page_Load<span class="br0">&#40;</span><span class="kw4">object</span> sender, EventArgs e<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Response.<span class="me1">StatusCode</span> <span class="sy0">=</span> <span class="nu0">404</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Once this is done, we still get the 302 redirect and then the 404 error code that should be returned:<br />
<img src="/wp-content/uploads/2009/02/hard404.png" alt="now firebug reports a correct 404 status code when we hit a url that doesn't exist"/></p>
<h2>Redirecting to the error page</h2>
<p>The ASP.NET custom error handling logic automatically redirects the user to your 404 error page. The only bad thing is they do a browser redirect rather than a server redirect so the url of the page changes for the user from the url that they typed in, to the url of your error page.</p>
<p>So if a user entered in a url like http://yoursite.com/fake.aspx they&#8217;d be redirected to http://yoursite.com/404.aspx?aspxerrorpath=/ErrorCodes/Fake.aspx.</p>
<p>It doesn&#8217;t seem very slick to me. If the user typed in the url manually they will probably get quite confused (and probably a little annoyed) when the url they typed in has suddenly changed. If they simply made a mistake they&#8217;ll need to type in the whole url again. The physical location of the error page just doesn&#8217;t seem like information that will be important to the user while the url of the page they were trying to access is. </p>
<p>The good news is that it&#8217;s quite easy to create a <a href="http://msdn.microsoft.com/en-us/library/ms227673.aspx">HttpHandler</a> that can listen for 404 errors and show the error page that is set up in the web.config without changing the url. </p>
<p>Here&#8217;s an example of what the code would look like. Notice that if you&#8217;re using a HttpModule to handle the 404 error pages, you can set the status code to the right thing in the module and don&#8217;t need to do it in the page:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">public</span> <span class="kw4">class</span> ErrorModule <span class="sy0">:</span> IHttpModule</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">void</span> Init<span class="br0">&#40;</span>HttpApplication context<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Listen for errors</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; context.<span class="me1">Error</span> <span class="sy0">+=</span> context_Error;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">void</span> context_Error<span class="br0">&#40;</span><span class="kw4">object</span> sender, EventArgs e<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; var context <span class="sy0">=</span> HttpContext.<span class="me1">Current</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// This example only handle 404 errors </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// You could also add some similar logic for 500 internal server</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// errors (logic errors) and do some logging</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; var error <span class="sy0">=</span> context.<span class="me1">Server</span>.<span class="me1">GetLastError</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw1">as</span> HttpException;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>error.<span class="me1">GetHttpCode</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">==</span> <span class="nu0">404</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// we can still use the web.config custom errors information to</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// decide whether to redirect</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var config <span class="sy0">=</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>CustomErrorsSection<span class="br0">&#41;</span>WebConfigurationManager.<span class="me1">GetSection</span><span class="br0">&#40;</span><span class="st0">&quot;system.web/customErrors&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>config.<span class="me1">Mode</span> <span class="sy0">==</span> CustomErrorsMode.<span class="me1">On</span> <span class="sy0">||</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>config.<span class="me1">Mode</span> <span class="sy0">==</span> CustomErrorsMode.<span class="me1">RemoteOnly</span> <span class="sy0">&amp;&amp;</span> context.<span class="me1">Request</span>.<span class="me1">Url</span>.<span class="me1">Host</span> <span class="sy0">!=</span> <span class="st0">&quot;localhost&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// set the response status code - if we set it here we don&#39;t need </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// to also set it in the page itself</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context.<span class="me1">Response</span>.<span class="me1">StatusCode</span> <span class="sy0">=</span> <span class="nu0">404</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// redirect to the 404 error page from the web.config</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>config.<span class="me1">Errors</span><span class="br0">&#91;</span><span class="st0">&quot;404&quot;</span><span class="br0">&#93;</span> <span class="sy0">!=</span> <span class="kw1">null</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HttpContext.<span class="me1">Current</span>.<span class="me1">Server</span>.<span class="me1">Transfer</span><span class="br0">&#40;</span>config.<span class="me1">Errors</span><span class="br0">&#91;</span><span class="st0">&quot;404&quot;</span><span class="br0">&#93;</span>.<span class="me1">Redirect</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HttpContext.<span class="me1">Current</span>.<span class="me1">Server</span>.<span class="me1">Transfer</span><span class="br0">&#40;</span>config.<span class="me1">DefaultRedirect</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>After the module is created it just needs to be registered in the httpModules section of the web.config file:</p>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;httpmodules<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;add</span> <span class="re0">name</span>=<span class="st0">&quot;ErrorModule&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;ErrorModule, App_Code&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/httpmodules<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p><a href="/wp-content/uploads/2009/02/error-codes.zip">Complete example</a></p>
<h2>Creating a good 404 experience</h2>
<p>Noone likes 404 errors but they&#8217;re a part of being online. To finish up, here are some ideas about what you can do to make the 404 pages on your site as useful as possible to the people who end up seeing them:</p>
<ul>
<li><a href="http://www.alistapart.com/articles/perfect404/">Ideas on how to turn a 404 into a good experience</a> from <a href="http://www.alistapart.com">A List Apart</a></li>
<li><a href="http://www.google.com/support/webmasters/bin/answer.py?answer=93641&#038;hl=en">Google guidelines</a> on how to make your 404 pages useful to visitors, search engines and developers</li>
<li><a href="https://www.google.com/webmasters/tools/">Google webmaster tools</a> has a 404 page widget you can add to your site that suggests what the user might actually have been looking for.
</li>
</ul>
<img src="http://feeds.feedburner.com/~r/helephant/~4/EEz8GDSroow" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/02/improving-the-way-aspnet-handles-404-requests/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2009/02/improving-the-way-aspnet-handles-404-requests/</feedburner:origLink></item>
		<item>
		<title>Date for OpenTech 09 announced</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/0ksc8M2KEjo/</link>
		<comments>http://helephant.com/2009/02/date-for-opentech-09-announced/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 20:37:15 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[Other stuff]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1266</guid>
		<description><![CDATA[One of my first and favourite UK conferences, OpenTech have just announced the date for 2009 is going to be July 4th. 
It&#8217;s got more of a beardy, open source, linux feel to it than DDD day does but that&#8217;s one of the things I like about it. The talks are always really interesting. One [...]]]></description>
			<content:encoded><![CDATA[<p>One of my first and favourite UK conferences, <a href="http://www.ukuug.org/events/opentech2009/">OpenTech</a> have just announced the date for 2009 is going to be July 4th. </p>
<p>It&#8217;s got more of a beardy, open source, linux feel to it than <a href="http://www.developerday.co.uk/ddd/default.asp">DDD day does</a> but that&#8217;s one of the things I like about it. The talks are always really interesting. One year they had a guy from the <a href="http://www.archive.org/">internet archive</a> talking about trying to scale up when they were trying to take a rolling snapshot of the internet. Last time I went there was a really interesting talk by a guy called <a href="http://en.wikipedia.org/wiki/Ted_Nelson">Ted Nelson</a> (who&#8217;s came up with the term hypertext) who talked about human-computer communication. </p>
<p>It&#8217;s always interesting and thought provoking (and only costs £5) so pencil it in to your geek diaries and head over to <a href="http://www.ukuug.org/events/opentech2009/list/">the notification mailing list</a> to get an email when registration opens. :) </p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/0ksc8M2KEjo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/02/date-for-opentech-09-announced/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2009/02/date-for-opentech-09-announced/</feedburner:origLink></item>
		<item>
		<title>Svelte asp.net: avoiding &lt;form runat=”server”&gt;</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/TBIhuq7iox0/</link>
		<comments>http://helephant.com/2009/02/svelte-aspnet-avoiding-form-runat-server/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 15:00:08 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[controls]]></category>

		<category><![CDATA[markup]]></category>

		<category><![CDATA[optimization]]></category>

		<category><![CDATA[plainoldhtml]]></category>

		<category><![CDATA[postback]]></category>

		<category><![CDATA[viewstate]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1138</guid>
		<description><![CDATA[Postbacks in ASP.NET have a pretty heavy cost in terms of page size. Add a &#60;form runat=&#8221;server&#8221;> tag and now you have a big ugly viewstate tag to lug around each time you load a new page. Put in a control that triggers postback (like a linkbutton) and suddenly there&#8217;s a big chunk of script [...]]]></description>
			<content:encoded><![CDATA[<p>Postbacks in ASP.NET have a pretty heavy cost in terms of page size. Add a &lt;form runat=&#8221;server&#8221;> tag and now you have a big ugly viewstate tag to lug around each time you load a new page. Put in a control that triggers postback (like a linkbutton) and suddenly there&#8217;s a big chunk of script and hidden fields where your nice simple form tag used to be:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;Default.aspx&quot; id=&quot;form1&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;input type=&quot;hidden&quot; name=&quot;__EVENTTARGET&quot; id=&quot;__EVENTTARGET&quot; value=&quot;&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;input type=&quot;hidden&quot; name=&quot;__EVENTARGUMENT&quot; id=&quot;__EVENTARGUMENT&quot; value=&quot;&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;input type=&quot;hidden&quot; name=&quot;__VIEWSTATE&quot; id=&quot;__VIEWSTATE&quot;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;value=&quot;/wEPDwUKLTkzNjc3NzczOWRk3iDWotjQ89h26Tx79TM3SRLPJlg=&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;script type=&quot;text/javascript&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">//&lt; ![CDATA[
</div>
</li>
<li class="li1">
<div class="de1">var theForm = document.forms[&#39;form1&#39;];
</div>
</li>
<li class="li1">
<div class="de1">if (!theForm) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; theForm = document.form1;
</div>
</li>
<li class="li1">
<div class="de1">}
</div>
</li>
<li class="li1">
<div class="de1">function __doPostBack(eventTarget, eventArgument) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; theForm.__EVENTTARGET.value = eventTarget;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; theForm.__EVENTARGUMENT.value = eventArgument;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; theForm.submit();
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }
</div>
</li>
<li class="li1">
<div class="de1">}
</div>
</li>
<li class="li1">
<div class="de1">//]]&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/script&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;input type=&quot;hidden&quot; name=&quot;__EVENTVALIDATION&quot; id=&quot;__EVENTVALIDATION&quot;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; value=&quot;/wEWAgLAqu2HBQKfwImNC6GfmgtYoNIWKohd9XTK5tBa39eY&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&#8230;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/form&gt;</div>
</li>
</ol>
</div>
<p>This is fine for a page that actually takes advantage of ASP.NET&#8217;s page lifecycle and controls, but can often be overkill for simple content driven applications that just need a little bit of server side logic. The good news is that in these cases you can have your serverside logic and eat it too just by using a simple html form tag with a regular GET request</p>
<h2>Before - markup only a mother could love</h2>
<p>The place I first thought of this was the search box on my old ASP.NET blog. Most of the pages on my blog were just straight content pages that didn&#8217;t need any of the postback logic. It seemed a real shame to add all this weight and complexity to the page just for a simple search form. </p>
<p>My search form was originally an ASP.NET form element with a button and textbox control that I could extract the search information from:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;form id=&quot;form2&quot; runat=&quot;server&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;asp :TextBox id=&quot;KeywordsField&quot; runat=&quot;server&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;asp :Button ID=&quot;SearchButton&quot; Text=&quot;Search&quot; runat=&quot;server&quot;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; onclick=&quot;SearchButton_Click&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/form&gt;</div>
</li>
</ol>
</div>
<p>The logic of redirecting to the search results page was a button click event with a Response.Redirect() call:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">protected</span> <span class="kw1">void</span> SearchButton_Click<span class="br0">&#40;</span><span class="kw4">object</span> sender, EventArgs e<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;Response.<span class="me1">Redirect</span><span class="br0">&#40;</span><span class="st0">&quot;search.aspx?keyword=&quot;</span> <span class="sy0">+</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;Server.<span class="me1">UrlEncode</span><span class="br0">&#40;</span>KeywordsField.<span class="me1">Text</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>The form HTML generated by ASP.NET looked like this:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;form name=&quot;form2&quot; method=&quot;post&quot; action=&quot;Before.aspx&quot; id=&quot;form2&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;input type=&quot;hidden&quot; name=&quot;__VIEWSTATE&quot; id=&quot;__VIEWSTATE&quot;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; value=&quot;/wEPDwULLTE0MDM4MzYxMjNkZB1GP1nffovgibqQWwhMKnQYMzMu&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;input type=&quot;hidden&quot; name=&quot;__EVENTVALIDATION&quot; id=&quot;__EVENTVALIDATION&quot;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value=&quot;/wEWAwLtu4u/AQLfh7nDDALR1viaCYZVWJZuOfJe5p1cdkVMqJHz7Q3T&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;input name=&quot;KeywordsField&quot; type=&quot;text&quot; id=&quot;KeywordsField&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;input type=&quot;submit&quot; name=&quot;SearchButton&quot; value=&quot;Search&quot; id=&quot;SearchButton&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/form&gt;</div>
</li>
</ol>
</div>
<h2>After - no server side code needed at all</h2>
<p>All the markup seemed like overkill to me so I switched the form with a regular HTML form element (minus the runat=&#8221;server&#8221; attribute). Then I replaced the textbox and button controls with their HTML equivalents:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;form action=&quot;Search.aspx&quot; method=&quot;get&quot;&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;input name=&quot;keywords&quot; type=&quot;text&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;input type=&quot;submit&quot; value=&quot;Search&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/form&gt;</div>
</li>
</ol>
</div>
<p><a href="/wp-content/uploads/2009/02/forms-without-postbacks.zip">Complete example</a></p>
<p>Now my search form doesn&#8217;t need code behind logic at all! The action=&#8221;search.aspx&#8221; attribute of the form tag tells the browser exactly where the information should be redirected to. The method=&#8221;get&#8221; part tells it to send it on the query string. The name of the form fields are used as the query string key. In my case the search page was expecting a query string parameter called keywords so the text field&#8217;s name also had to be set to &#8220;keywords&#8221;. </p>
<p>So when the search button was clicked, the browser would try to load the following url (exactly what my old redirect was loading):<br />
http://mysite.com/search.aspx?keywords=hello+world</p>
<p>The html generated now is still the same svelte markup I started with:</p>
<pre>
&lt;form action="Search.aspx" method="get">
    &lt;input name="keywords" type="text" />
    &lt;input type="submit" value="Search" />
&lt;/form>
</pre>
<p><strong>Note</strong>: it&#8217;s important not to put a runat=&#8221;server&#8221; attribute on the form fields because ASP.NET will change the name of the fields to something that&#8217;s guaranteed to be unique on the page. This is fine when you are using the fields in a postback but may mean that the values passed to the next page won&#8217;t have the right names.</p>
<h2>For <a href="http://sqldev.wordpress.com/">Barry</a> :)</h2>
<p>Q: why not just use <a href="http://www.asp.net/mvc/">Microsoft&#8217;s MVC framework</a> so you never have to use postbacks?<br />
A: You don&#8217;t always get to choose what you&#8217;re going to develop in and there&#8217;s an awful lot of WebForms code out there already that sometimes you just have to work with. :)</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/TBIhuq7iox0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/02/svelte-aspnet-avoiding-form-runat-server/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2009/02/svelte-aspnet-avoiding-form-runat-server/</feedburner:origLink></item>
		<item>
		<title>Opening resx files in the xml editor</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/bFRx_KhJ2wI/</link>
		<comments>http://helephant.com/2009/02/opening-resx-files-in-the-xml-editor/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 16:39:20 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[Visual Studio]]></category>

		<category><![CDATA[customization]]></category>

		<category><![CDATA[resx]]></category>

		<category><![CDATA[tools]]></category>

		<category><![CDATA[visualstudio]]></category>

		<category><![CDATA[vs2008]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1172</guid>
		<description><![CDATA[Defaults can never please everyone. There&#8217;s always someone whose workflow is a little different. That one developer who likes to use SeaMonkey to test their pages or that weirdo who prefers to edit resx files as a text file.
I am that weirdo who likes to edit resx files as text files and rather than argue [...]]]></description>
			<content:encoded><![CDATA[<p>Defaults can never please everyone. There&#8217;s always someone whose workflow is a little different. That one developer who likes to use <a href="http://www.seamonkey-project.org/">SeaMonkey</a> to test their pages or that weirdo who prefers to edit resx files as a text file.</p>
<p>I am that weirdo who likes to edit resx files as text files and rather than argue with me about the merits of their GUI tool, they have given me a very nice dialog where I can choose what editor I&#8217;d like any type of Visual Studio project file to open with by default. </p>
<p>If you are another person who shuns the built in editor and wonders where the &#8220;switch to xml button&#8221; went in VS2008, fear not because here are instructions on how to change the very nature of VS2008 and make it do your unnatural resx text editing bidding:</p>
<ol>
<li>Right flick on a resx file</li>
<li>Choose open with</li>
<li>Select <strong>Xml Editor</strong></li>
</ol>
<p><img src="/wp-content/uploads/2009/02/openwith.png" alt="the open with dialog"/></p>
<p>Also works on any other type of file in visual studio. It&#8217;s also very handy for opening .skin files with intellisense support. For any SeaMonkey developers, Check out right click->browse with to change what browser different file types will be browsed with. </p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/bFRx_KhJ2wI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/02/opening-resx-files-in-the-xml-editor/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2009/02/opening-resx-files-in-the-xml-editor/</feedburner:origLink></item>
		<item>
		<title>Snowy London Underground sign</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/MfeuikfBJxw/</link>
		<comments>http://helephant.com/2009/02/snowy-london-underground/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 14:49:04 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[Other stuff]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1254</guid>
		<description><![CDATA[It&#8217;s a snowy day in London today. Apparently the most snow London&#8217;s seen in 20 years. It&#8217;s definitely the most snow I&#8217;ve ever seen. I was covered in snow and looking like a big white yeti by the time I got to the station this morning.
I&#8217;ve been keeping an eye on the Transport for London [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a snowy day in London today. Apparently the <a href="http://news.bbc.co.uk/1/hi/uk/7864395.stm">most snow London&#8217;s seen in 20 years</a>. It&#8217;s definitely the most snow I&#8217;ve ever seen. I was covered in snow and looking like a big white yeti by the time I got to the station this morning.</p>
<p>I&#8217;ve been keeping an eye on the <a href="http://www.tfl.gov.uk/">Transport for London</a> website all day (hoping Joe doesn&#8217;t get stuck in town) and loved the picture they had on the homepage:</p>
<p><img src="/wp-content/uploads/2009/02/snowy-tfl.png" alt="Snowy underground sign"/></p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/MfeuikfBJxw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/02/snowy-london-underground/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2009/02/snowy-london-underground/</feedburner:origLink></item>
		<item>
		<title>Reducing viewstate on custom controls</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/3i19pGZ-iPo/</link>
		<comments>http://helephant.com/2009/02/reducing-viewstate-on-custom-controls/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 11:32:13 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[ASP.NET]]></category>

		<category><![CDATA[Server controls]]></category>

		<category><![CDATA[attributes]]></category>

		<category><![CDATA[controls]]></category>

		<category><![CDATA[customccontrols]]></category>

		<category><![CDATA[optimization]]></category>

		<category><![CDATA[pagesize]]></category>

		<category><![CDATA[viewstate]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1118</guid>
		<description><![CDATA[One of the biggest waste I see in using viewstate is that it persists values that are already set in the aspx. These get set every time that the page runs and don&#8217;t need to be round tripped to the browser so that they will be persisted. 
I did a little experiment a while back [...]]]></description>
			<content:encoded><![CDATA[<p>One of the biggest waste I see in using viewstate is that it persists values that are already set in the aspx. These get set every time that the page runs and don&#8217;t need to be round tripped to the browser so that they will be persisted. </p>
<p>I did a little experiment a while back where I tried <a href="/2008/08/saving-server-control-properties-to-viewstate-with-custom-attributes/">using custom attributes to save viewstate</a> on controls. I found that while it was very handy being able to save properties in  viewstate without having to write repetitive code, a much bigger advantage was I now had one place where I could optimize exactly what went into it.</p>
<p>The problem with persisting values in viewstate that are already saved in the aspx is pretty easy to solve. The code just needs to keep track of what the values of the properties were after the controls in aspx page are initialized:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">protected</span> <span class="kw1">override</span> <span class="kw1">void</span> OnInit<span class="br0">&#40;</span><span class="kw5">System</span>.<span class="me1">EventArgs</span> e<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">base</span>.<span class="me1">OnInit</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;List<span class="sy0">&lt;</span>propertyinfo<span class="sy0">&gt;</span> viewstateProperties <span class="sy0">=</span> GetViewStateProperties<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">foreach</span> <span class="br0">&#40;</span>PropertyInfo property <span class="kw1">in</span> viewstateProperties<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; _initialValues<span class="br0">&#91;</span>property.<span class="me1">Name</span><span class="br0">&#93;</span> <span class="sy0">=</span> property.<span class="me1">GetValue</span><span class="br0">&#40;</span><span class="kw1">this</span>, <span class="kw1">null</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">private</span> List<span class="sy0">&lt;/</span>propertyinfo<span class="sy0">&gt;&lt;</span>propertyinfo<span class="sy0">&gt;</span> GetViewStateProperties<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;List<span class="sy0">&lt;/</span>propertyinfo<span class="sy0">&gt;&lt;</span>propertyinfo<span class="sy0">&gt;</span> properties <span class="sy0">=</span> <span class="kw3">new</span> List<span class="sy0">&lt;/</span>propertyinfo<span class="sy0">&gt;&lt;</span>propertyinfo<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">foreach</span> <span class="br0">&#40;</span>PropertyInfo property <span class="kw1">in</span> <span class="kw1">this</span>.<span class="me1">GetType</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">GetProperties</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">object</span><span class="br0">&#91;</span><span class="br0">&#93;</span> attributes <span class="sy0">=</span> property.<span class="me1">GetCustomAttributes</span><span class="br0">&#40;</span><span class="kw3">typeof</span><span class="br0">&#40;</span>PersistToViewState<span class="br0">&#41;</span>, <span class="kw1">true</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>attributes.<span class="me1">Length</span> <span class="sy0">&gt;</span> <span class="nu0">0</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;properties.<span class="me1">Add</span><span class="br0">&#40;</span>property<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">return</span> properties;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>propertyinfo<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>Then when it&#8217;s time to save the viewstate, check whether the value has actually changed:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">protected</span> <span class="kw1">override</span> <span class="kw4">object</span> SaveViewState<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">// Save automatic viewstate properties</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;List<span class="sy0">&lt;</span>propertyinfo<span class="sy0">&gt;</span> viewstateProperties <span class="sy0">=</span> GetViewStateProperties<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> x <span class="sy0">=</span> <span class="nu0">0</span>; x <span class="sy0">&lt;</span> viewstateProperties.<span class="me1">Count</span>; x<span class="sy0">++</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; PropertyInfo property <span class="sy0">=</span> viewstateProperties<span class="br0">&#91;</span>x<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">object</span> value <span class="sy0">=</span> property.<span class="me1">GetValue</span><span class="br0">&#40;</span><span class="kw1">this</span>, <span class="kw3">new</span> <span class="kw4">object</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#123;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>_initialValues.<span class="me1">ContainsKey</span><span class="br0">&#40;</span>property.<span class="me1">Name</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// Only save the property to viewstate if it has changed since viewstate </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// was loaded. If it hasn&#39;t been changed, we don&#39;t need to store it because</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// it will be loaded from the aspx on the next page load</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw4">object</span> initialValue <span class="sy0">=</span> _initialValues<span class="br0">&#91;</span>property.<span class="me1">Name</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw4">object</span>.<span class="me1">Equals</span><span class="br0">&#40;</span>initialValue, value<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; ViewState<span class="br0">&#91;</span>x.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#93;</span> <span class="sy0">=</span> value;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;ViewState<span class="br0">&#91;</span>x.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#93;</span> <span class="sy0">=</span> value;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">return</span> <span class="kw1">base</span>.<span class="me1">SaveViewState</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><a href="/wp-content/uploads/2009/02/reduce-viewstate.zip">Complete example</a></p>
<p>It makes a big difference to how much viewstate is saved. Here&#8217;s the viewstate of a single example Pie control before this simple bit of optimization:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;input type=&quot;hidden&quot; name=&quot;__VIEWSTATE&quot; id=&quot;__VIEWSTATE&quot;
</div>
</li>
<li class="li1">
<div class="de1">value=&quot;/wEPDwUJMzUzODE3ODMxD2QWAgIDD2QWAgIBDxYEHgEwBQlhcHBsZSBwaWUe
</div>
</li>
<li class="li1">
<div class="de1">ATECA2Rk/V7Nc8+xuVAMsS4R9hLs1SHD4Js=&quot; /&gt;</div>
</li>
</ol>
</div>
<p>Here&#8217;s the viewstate after:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;input type=&quot;hidden&quot; name=&quot;__VIEWSTATE&quot; id=&quot;__VIEWSTATE&quot;
</div>
</li>
<li class="li1">
<div class="de1">value=&quot;/wEPDwUJMzUzODE3ODMxZGTnlfN1SaJSDVcRTDQPIBVe1fK+Gw==&quot; /&gt;</div>
</li>
</ol>
</div>
<p>Everything else still works as expected. Controls created entirely in code will still work perfectly well, the only difference will be that all properties that are set will need to be persisted so you won&#8217;t see any reduction in the amount of viewstate used there. The properties set in code of controls created in the aspx will also be saved to viewstate so they will be persisted after the next postback. </propertyinfo></pre>
<img src="http://feeds.feedburner.com/~r/helephant/~4/3i19pGZ-iPo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/02/reducing-viewstate-on-custom-controls/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2009/02/reducing-viewstate-on-custom-controls/</feedburner:origLink></item>
		<item>
		<title>Goodbye 2008. Hello 2009</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/aRtqgLTCt_Q/</link>
		<comments>http://helephant.com/2009/01/goodbye-2008-and-hello-2009/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 16:48:51 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[Other stuff]]></category>

		<category><![CDATA[2008]]></category>

		<category><![CDATA[2009]]></category>

		<category><![CDATA[goals]]></category>

		<category><![CDATA[newyears]]></category>

		<category><![CDATA[newyearsresolution]]></category>

		<guid isPermaLink="false">http://helephant.net/?p=1017</guid>
		<description><![CDATA[Wow, it&#8217;s January 18th already. I feel like I&#8217;ve really hit the ground running. Everyone else who did their new years post did them two weeks ago but I really wanted to write down what I&#8217;d achieved in 2008 and what I wanted to achieve in 2009 to give myself something to look at in [...]]]></description>
			<content:encoded><![CDATA[<p>Wow, it&#8217;s January 18th already. I feel like I&#8217;ve really hit the ground running. Everyone else who did their new years post did them two weeks ago but I really wanted to write down what I&#8217;d achieved in 2008 and what I wanted to achieve in 2009 to give myself something to look at in a year. </p>
<h2>What I did in 2008</h2>
<p>Participated in the UK ASP.NET community - I talked at <a href="http://idunno.org">Barry&#8217;s</a> <a href="http://www.nxtgenug.net/Profile.aspx?UserID=e8b4e892-68a6-4445-b4e3-e01f201f357f">user group</a>, <a href="http://www.vbug.co.uk/">VBUG</a> and <a href="http://www.developerday.co.uk/ddd/agendaddd7lineup.asp">DDD7</a>. It was exhausting but great fun. The feedback I got from DDD7 was particularly useful and I think at some point I&#8217;ll be able to get hold of a video to see how my talk actually goes from the audience&#8217;s perspective. </p>
<p>Learnt heaps about <a href="/2008/08/building-objects-with-javascript/">javascript objects</a> - I&#8217;m embarrassed to admit that I didn&#8217;t even know what <a href="/2008/10/javascript-closures/">closures</a> were at the beginning of 2008. I think learning more about javascript has made me a better programmer in general. It&#8217;s really made this C# dev very keen to have a go at a more dynamic language like ruby or python. </p>
<p>Move my site to <a href="http://www.wordpress.org">wordpress</a> - I had great fun writing my own blog script. It&#8217;s practically a web developer rite of passage. After seeing all the cool stuff other people were able to do on their blogs, <a href="http://updatepanel.net/">Ting</a> convinced me it was time to retire the old ASP.NET script and use my tiny bit of home dev time to work on something more important. </p>
<p>Started a new job - been working at my current job for almost a year now. I&#8217;m still working as an ASP.NET developer (which I pretty much love). I got lucky *again* to find a friendly place with dedicated and interesting people. Got to learn about LINQ, JQuery, some neat clientside bugs and how to fit German words into layouts. </p>
<p><a href="http://www.flickr.com/photos/helephant/sets/72157607462892965/">Went to Tokyo</a> - the land of robots, <a href="http://www.flickr.com/photos/helephant/2884376396/in/set-72157607462892965/">hello kitty</a> and amazing tasting chicken. <a href="http://www.flickr.com/photos/nekojoe/2883973279/in/set-72157607478297478/">Akihabara</a> is where good geeks go when they die. </p>
<p>Lost 50 pounds - I am still a little surprised I actually managed to do this. I followed <a href="http://www.weightwatchers.co.uk/">weight watchers</a> all year and found it really helpful. There were times when it was hard and I didn&#8217;t make much progress in the last three months of the year but I&#8217;m pretty proud I&#8217;ve managed to do so well. Slightly embarrassed my weight got to the point where I needed to lose 50 pounds, but pretty relieved I was able to do it. </p>
<p><a href="/2008/11/big-non-technical-helen-news/">Got engaged</a> to <a href="http://www.otakunews.com">Joe</a> - can&#8217;t really take credit for that. It was his idea. :D</p>
<h2>Goals for 2009</h2>
<p>Seems like I always want to do way more than I have time for so I&#8217;ve decided just to pick a couple of extra-circular things to concentrate on in 2009. To be honest, I&#8217;ll be happy to complete any of these things. </p>
<p>Write some more interesting clientside samples - every year for the last 11 years I&#8217;ve been lucky enough to expand my clientside web development skills without really trying to. This year I want to consciously push the boundaries of the web app a little bit. I have a few things in mind. :)</p>
<p>Launch a new site - I&#8217;ve got a few ideas about what I&#8217;d like to do this year. I don&#8217;t want to actually announce anything yet but I started something last year that I hope will be ready for version 1.0 in a month or two. </p>
<p>Post at least twice a month - Attwood says <a href="http://www.codinghorror.com/blog/archives/000983.html">pick a schedule and stick to it</a>. I know it&#8217;s not going to always be possible but I&#8217;m going to try for twice a month. Then my plan is to use my wee bit of spare time to do something else for the rest of the month. </p>
<p>Organise our wedding - oh my goodness that&#8217;s turning out to be a lot of work already. I&#8217;ve spent every lunch time since I got back to work on the 5th sorting something out and I don&#8217;t seem to be able to have a conversation with my mum or his that doesn&#8217;t involve wedding favours, invitation lists or dresses. It&#8217;s really good fun though and I think we&#8217;re going to have a great day. :)</p>
<p>Finish the last bit of weight loss - I&#8217;m still not down to my ideal weight. My BMI is still at the top end of the healthy range. I&#8217;d like to get it to a little below the middle (really, I just want to lose the flab around my tummy). I&#8217;m not far away now. I think it should take about three months to lose the last little bit. Then I&#8217;ve just got to get used to the idea of healthy living for the rest of my life. :)</p>
<h2>Things I&#8217;d like to do but won&#8217;t have time for</h2>
<p>Get involved in an open source project - preferably something to do with javascript. The more web development I do the more I&#8217;m discovering how much I like front end development. </p>
<p>Learn hiragana - managed to learn all the characters by studying a book on the train. Would like to be able to read a little (and understand the japanese language a little) when Joe and I go on our honeymoon.</p>
<p>Read some more - read all of Jane Austen&#8217;s book in 2007. Read a heap of great sci-fi (and all of Harry Potter) in 2008. Hope I get some time to do some great fiction reading in 2009 as well. Commuting to work isn&#8217;t all bad. :)</p>
<p>World domination through army of killer robots - you lot are just lucky I&#8217;m too busy for this. :)</p>
<p>Get to the end of the year without being exhausted. :)</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/aRtqgLTCt_Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/01/goodbye-2008-and-hello-2009/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2009/01/goodbye-2008-and-hello-2009/</feedburner:origLink></item>
		<item>
		<title>Javascript object prototype</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/Cg6pjeyBrXA/</link>
		<comments>http://helephant.com/2009/01/javascript-object-prototype/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 16:08:11 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[inheritance]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[javascriptobjects]]></category>

		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://helephant.net/?p=410</guid>
		<description><![CDATA[The javascript object prototype is javascript&#8217;s way of sharing implementation across similar objects, much like the way classes are used to do this in many other languages. Although constructor functions look a lot like classes, javascript does not have a class based object system like C# or Java. Instead it has a prototype based object [...]]]></description>
			<content:encoded><![CDATA[<p>The javascript object prototype is javascript&#8217;s way of sharing implementation across similar objects, much like the way classes are used to do this in many other languages. Although <a href="/2008/09/constructor-functions/">constructor functions</a> look a lot like classes, <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Class-Based_vs._Prototype-Based_Languages">javascript does not have a class based object</a> system like C# or Java. Instead it has a <a href="http://en.wikipedia.org/wiki/Prototype-based_programming">prototype based</a> object system.</p>
<p>The main difference between the two types of languages is all about objects and classes. In a class based language there is a clear distinction between the ideas of a class and an object. A class is a template for creating an object and an object is a specific instance of a class. In C# you cannot create an object without instantiating it from a class. Even the most basic object of type Object is instantiated from a class. Once the object is created you cannot make it into a different type of object by adding different properties.</p>
<p>In a prototype based systems there are no classes. All objects are created by adding properties and methods to an empty object or by cloning an existing one. Although a constructor function may look like a class (probably so people from more traditional class based languages would be able to use it), it’s really just a function that knows how to add the right properties and methods to create a particular type of object.</p>
<p>This approach is called prototype-based inheritance because an existing object is used as a template (or a <a href="http://www.askoxford.com/concise_oed/prototype?view=uk">prototype - a typical example</a>) to build other objects. The existing object will be used as a starting point to build the new object but the new object does not have to be exactly the same. </p>
<h2>How it works in javascript</h2>
<p>Prototypes are implemented in javascript using the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function/prototype">prototype property</a> of constructor functions. Any property or method that&#8217;s added to the constructor&#8217;s prototype automatically becomes part of every object created by that function. </p>
<p>The prototype property is basically a template for the objects created by the constructor. It contains the things that should be the same among all objects created by the constructor. Individual objects can override and change the things they inherit from the constructor&#8217;s prototype but they will all start out the same. </p>
<p>The aim of the prototype is to share implementation between similar objects, to make things more convenient for programmers. It is not designed to be a type system. Javascript objects are dynamic so they can be changed after they are created. Knowing that an object was created by a particular constructor function does not guarantee anything about the methods or properties that an object will have. </p>
<h3>A simple example</h3>
<p>The easiest way to understand this is to look at an example, so let&#8217;s take a look at the <a href="/2008/09/constructor-functions/">Pet example</a> again. </p>
<p>All the pets created by the pet constructor function have a sayHello() method. When we created our pet using the constructor function, we created a separate sayHello() function for each pet by creating the function and adding it to the new object we were creating:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> Pet<span class="br0">&#40;</span><span class="kw3">name</span>, species, hello<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw3">name</span> = <span class="kw3">name</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">species</span> = species;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">hello</span> = hello;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">sayHello</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">hello</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Wouldn&#8217;t it be better if there would be  just one sayHello() function that all the pet objects will automatically share? To do this we could remove the sayHello() method from the constructor function and add it to the function&#8217;s prototype property instead:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> Pet<span class="br0">&#40;</span><span class="kw3">name</span>, species, hello<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw3">name</span> = <span class="kw3">name</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">species</span> = species;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">hello</span> = hello;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Pet.<span class="me1">prototype</span>.<span class="me1">sayHello</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">hello</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="kw2">new</span> Pet<span class="br0">&#40;</span><span class="st0">&quot;Rufus&quot;</span>, <span class="st0">&quot;cat&quot;</span>, <span class="st0">&quot;miaow&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">sayHello</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="/wp-content/uploads/2009/01/prototype-simple.html">Complete example</a></p>
<p>When we created the Pet function, its prototype property was automatically set to an empty object. Every function is set up this way when it&#8217;s created because there&#8217;s no way for javascript to know whether any particular function will be used as a constructor function or not. </p>
<p>We wanted all our pets to have a sayHello method, so we added a sayHello() method to the Pet&#8217;s prototype property. The prototype property contains a <a href="/2008/08/building-simple-objects/">regular javascript object</a> so this is just the same as assigning a new method or property to any other object. In this case we have created a new <a href="/2008/08/javascript-anonymous-functions/">anonymous function</a> and assigned it to a property called sayHello. </p>
<p>When we created the rufus object, it automatically maintained an invisible link back to the Pet function that created it. Then when we tried to access the sayHello() method, javascript first looked for a sayHello() method set directly on the rufus object. When it couldn&#8217;t find one, it then looked at the Pet constructor&#8217;s prototype, found sayHello() and called that instead. </p>
<p>Because the property resolution happens when the property is called, any changes made to the prototype property will be reflected in all of the objects already created by the constructor. Properties can be dynamically added or removed or the prototype could even be replaced with an entirely new object. </p>
<p>This all happens transparently. The code that is using the rufus object doesn&#8217;t need to care whether rufus&#8217; sayHello() method was set directly on rufus or if it belongs to the Pet constructor. </p>
<h2>The prototype property is just an object</h2>
<p>The prototype property is just an object. There&#8217;s nothing particularly special or magic about it. Anything you can do to a normal object you can also do to a function&#8217;s prototype property. This includes adding and removing properties, accessing the properties through substring (Pet.prototype["property"]) or dot (Pet.prototype.property) notation and iterating through the properties using a for loop. </p>
<p>When a new function is created the prototype property is set to an empty object, exactly the same if we said Pet.prototype = new Object() when we created the function. Javascript does this by default whenever you create a new function to make sure that any objects created by calling the function will automatically get all of the methods and properties that are belong to every <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a> (like toString()). </p>
<p>In the previous example we just added another property to object that was automatically created. Instead we could have overriden the default empty object with a new one instead:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">Pet.<span class="me1">prototype</span> = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; sayHello : <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">hello</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
</ol>
</div>
<p>You can even set the prototype to an be a new object created by another constructor. This is called prototype chaining and is the way related javascript objects can share implementation much like inheritance in a class based language:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> Cat<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">Cat.<span class="me1">prototype</span> = <span class="kw2">new</span> Pet<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<h2>Every constructor has a prototype property</h2>
<p>Even built in constructors like String or Array. Libraries like <a href="http://www.prototypejs.org/">prototype</a> and <a href="http://ajax.asp.net">ASP.NET ajax</a> use this to add functions to the built in types like <a href="http://www.prototypejs.org/api/array/reverse">Array.reverse()</a> or <a href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/Global/JavascriptTypeExtensions/StringTypeExt/StringTrimFunc.aspx">String.trim()</a>. </p>
<p>Here&#8217;s a simple example that adds a sheep function to all javascript string objects:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">String.<span class="me1">prototype</span>.<span class="me1">sheep</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;baaah &quot;</span> + <span class="kw1">this</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> hello = <span class="st0">&quot;hello world&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span>hello.<span class="me1">sheep</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="/wp-content/uploads/2009/01/prototype-extending-built-in-constructors.html">Complete example</a>.</p>
<h2>Why is this important?</h2>
<p>The practical reason why this is important is sharing single a method between all objects uses less memory than having a separate copy for each object. This can be a big advantage when working on a complicated web application with lots of objects. </p>
<p>The javascript object prototype also enables you use some interesting coding patterns like inheritance and object cloning to more easily share implementation between similar objects in a similar way to how you would use classes to do this in a class based language.</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/Cg6pjeyBrXA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/01/javascript-object-prototype/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2009/01/javascript-object-prototype/</feedburner:origLink></item>
		<item>
		<title>Javascript null or default operator</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/oG-4BBADlRQ/</link>
		<comments>http://helephant.com/2008/12/javascript-null-or-default-operator/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 20:39:51 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://helephant.net/?p=1010</guid>
		<description><![CDATA[A neat little trick I learnt from Ting is a way to check whether a value was null or undefined using the or operator (&#124;&#124;). 
It&#8217;s really simple. If valueThatMightBeEmpty has a value set, you get that value. If it is null you get the default. It&#8217;s just like the ?? operator in C#:



var value [...]]]></description>
			<content:encoded><![CDATA[<p>A neat little trick I learnt from <a href="http://updatepanel.net/">Ting</a> is a way to check whether a value was null or undefined using the <a href="http://docs.sun.com/source/816-6408-10/ops.htm#1044813">or operator (||)</a>. </p>
<p>It&#8217;s really simple. If valueThatMightBeEmpty has a value set, you get that value. If it is null you get the default. It&#8217;s just like the ?? operator in C#:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> value = valueThatMightBeEmpty <span class="sy0">||</span> defaultValue;</div>
</li>
</ol>
</div>
<h2>A real example</h2>
<p>A really handy place to do this is event handling code. It&#8217;s a classically annoying bit of web development where the event information will be stored in a global variable called event for IE and in the first parameter passed to the event handler (I usually call it e) in other browsers. </p>
<p>So you might write some code that looks like this to get an event object that you can use in all browsers:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">if</span><span class="br0">&#40;</span><span class="sy0">!</span>e<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; e = event;</div>
</li>
</ol>
</div>
<p>Instead you could just use the or operator (||) to check whether the variable was null and return a reference to the event object if it is:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">e = e <span class="sy0">||</span> event;</div>
</li>
</ol>
</div>
<p><a href="/wp-content/uploads/2008/12/javascriptor.html">Complete example</a></p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/oG-4BBADlRQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2008/12/javascript-null-or-default-operator/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2008/12/javascript-null-or-default-operator/</feedburner:origLink></item>
		<item>
		<title>Big (non-technical) Helen news</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/Goj9ECr8Kh4/</link>
		<comments>http://helephant.com/2008/11/big-non-technical-helen-news/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 20:38:06 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[Other stuff]]></category>

		<guid isPermaLink="false">http://helephant.net/?p=1006</guid>
		<description><![CDATA[This is a tech blog but I just wanted to share a little bit of big Helen-life news with the friends of mine who read it. Joe, my boyfriend of four years, proposed to me on Friday night very romantically on the London eye and I said yes (of course!). I&#8217;ve been grinning like mad [...]]]></description>
			<content:encoded><![CDATA[<p>This is a tech blog but I just wanted to share a little bit of big Helen-life news with the friends of mine who read it. Joe, my boyfriend of four years, proposed to me on Friday night very romantically on the London eye and I said yes (of course!). I&#8217;ve been grinning like mad all weekend and never thought it was even possible to be so happy! :)</p>
<p>The funny part was after I changed my status to engaged on facebook I started seeing a whole lot of wedding relatd adverts (and diets). :)<br />
<img src="/wp-content/uploads/2009/01/facebook.png"/></p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/Goj9ECr8Kh4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2008/11/big-non-technical-helen-news/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2008/11/big-non-technical-helen-news/</feedburner:origLink></item>
		<item>
		<title>Bleeding edge of web slides and samples</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/Me0GIusNCD8/</link>
		<comments>http://helephant.com/2008/11/bleeding-edge-of-web-slides-and-samples/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 20:35:07 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[Community]]></category>

		<category><![CDATA[My presentations]]></category>

		<guid isPermaLink="false">http://helephant.net/?p=999</guid>
		<description><![CDATA[I did a presentation about the bleeding edge of web at the DDD7 uk community conference last weekend. Here&#8217;s the complete talk including slides, samples and a list of bullet points that I talked about including the urls of any website that I linked to during the talk. 
Please feel free to use my talk
Do [...]]]></description>
			<content:encoded><![CDATA[<p>I did a presentation about the <a href="/tags/bleedingedgeofweb/">bleeding edge of web</a> at the <a href="http://www.developerday.co.uk/">DDD7</a> uk community conference last weekend. Here&#8217;s the <a href="/wp-content/uploads/2009/11/bleeding.zip">complete talk</a> including slides, samples and a list of bullet points that I talked about including the urls of any website that I linked to during the talk. </p>
<h2>Please feel free to use my talk</h2>
<p>Do you have a local user group in your area that might be interested? I&#8217;ve licensed my presentation under creative commons so you&#8217;re welcome to take the slides and the code and to give the talk yourself. Or use it as a starting point for your own talk. </p>
<h2>Licensed under creatives commons</h2>
<p><a rel="license" href="http://creativecommons.org/licenses/by/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by/3.0/88x31.png" /></a><br /><span xmlns:dc="http://purl.org/dc/elements/1.1/" property="dc:title">Building objects with javascript </span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://www.helephant.com" property="cc:attributionName" rel="cc:attributionURL">Helen Emerson</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported License</a>.<br />Based on a work at <a xmlns:dc="http://purl.org/dc/elements/1.1/" href="http://www.helephant.com/article.aspx?ID=1223  " rel="dc:source">www.helephant.com</a>.<br />Permissions beyond the scope of this license may be available at <a xmlns:cc="http://creativecommons.org/ns#" href="http://www.helephant.com" rel="cc:morePermissions">http://www.helephant.com</a>.</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/Me0GIusNCD8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2008/11/bleeding-edge-of-web-slides-and-samples/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2008/11/bleeding-edge-of-web-slides-and-samples/</feedburner:origLink></item>
		<item>
		<title>Decommissioning pixel origami feed</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/K1GH00CUoyM/</link>
		<comments>http://helephant.com/2008/11/decommissioning-pixel-origami-feed/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 20:33:21 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[Other stuff]]></category>

		<category><![CDATA[site]]></category>

		<guid isPermaLink="false">http://helephant.net/?p=995</guid>
		<description><![CDATA[I&#8217;m going to decommission the old pixel origami feed. Could anyone still using it please switch to http://feeds.feedburner.com/helephant instead? 
I was hoping this would be seamless but I messed up switching the pixel origami feed over to the helephant feed so it&#8217;s now pointing to the real feed url instead. This should work fine (and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going to decommission the old pixel origami feed. Could anyone still using it please switch to <a href="http://feeds.feedburner.com/helephant">http://feeds.feedburner.com/helephant</a> instead? </p>
<p>I was hoping this would be seamless but I messed up switching the pixel origami feed over to the helephant feed so it&#8217;s now pointing to the real feed url instead. This should work fine (and I&#8217;m going to redirect it to the helephant feedburner feed when I hopefully switch my blog to wordpress in the near future) so don&#8217;t worry too much but if it suddenly stops working this is why. </p>
<p>Sorry about the hassle! </p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/K1GH00CUoyM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2008/11/decommissioning-pixel-origami-feed/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2008/11/decommissioning-pixel-origami-feed/</feedburner:origLink></item>
		<item>
		<title>Changing firebug’s font size</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/-aez629jXqk/</link>
		<comments>http://helephant.com/2008/11/changing-firebugs-font-size/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 20:31:36 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[Tools]]></category>

		<category><![CDATA[firebug]]></category>

		<category><![CDATA[presentations]]></category>

		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://helephant.net/?p=991</guid>
		<description><![CDATA[One problem I&#8217;ve had a couple of times when using Firebug to show things during code demos is I haven&#8217;t been able to make the font big enough for people at the back to read it. 
I found the solution at stack overflow:
1. Open firebug in new window
2. Go to the view->text size menu
3. Close [...]]]></description>
			<content:encoded><![CDATA[<p>One problem I&#8217;ve had a couple of times when using Firebug to show things during code demos is I haven&#8217;t been able to make the font big enough for people at the back to read it. </p>
<p>I found the solution at <a href="http://stackoverflow.com/questions/260008/increase-the-font-size-in-firebug">stack overflow</a>:<br />
1. Open firebug in new window<br />
2. Go to the view->text size menu<br />
3. Close the window and it should be the right size when you reopen it. </p>
<p><img src="/wp-content/uploads/2009/01/firebug.png" alt="view-/>text size->increase text size&#8221;></p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/-aez629jXqk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2008/11/changing-firebugs-font-size/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2008/11/changing-firebugs-font-size/</feedburner:origLink></item>
		<item>
		<title>VBUG London javascript objects presentation</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/5L439mVRZIM/</link>
		<comments>http://helephant.com/2008/11/vbug-london-javascript-objects-presentation/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 20:27:56 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[Community]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[javascriptobjects]]></category>

		<category><![CDATA[objects]]></category>

		<category><![CDATA[slides]]></category>

		<category><![CDATA[usergroup]]></category>

		<guid isPermaLink="false">http://helephant.net/?p=986</guid>
		<description><![CDATA[I just got back from doing a talk about javascript objects at London VBUG. Thanks to everyone who came! I really enjoyed doing the talk and all the great questions you guys asked.
Anyway I promised to put links up to all the relevant stuff from my talk. I&#8217;ve uploaded my slides and samples. I&#8217;m also [...]]]></description>
			<content:encoded><![CDATA[<p>I just got back from doing a talk about javascript objects at London <a href="http://www.vbug.co.uk">VBUG</a>. Thanks to everyone who came! I really enjoyed doing the talk and all the great questions you guys asked.</p>
<p>Anyway I promised to put links up to all the relevant stuff from my talk. I&#8217;ve uploaded my <a href="/2008/08/object-oriented-javascript-slides-and-samples/">slides and samples</a>. I&#8217;m also writing up a set of articles about <a href="/2008/08/building-objects-with-javascript/">javascript objects</a>. </p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/5L439mVRZIM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2008/11/vbug-london-javascript-objects-presentation/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2008/11/vbug-london-javascript-objects-presentation/</feedburner:origLink></item>
		<item>
		<title>Dust-me selector tool for finding unused CSS selectors</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/GIb6pSF9iWc/</link>
		<comments>http://helephant.com/2008/10/dust-me-selector-tool-for-finding-unused-css-selectors/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 09:08:59 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[CSS]]></category>

		<category><![CDATA[Tools]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[debugging]]></category>

		<category><![CDATA[dustmeselectors]]></category>

		<category><![CDATA[extension]]></category>

		<category><![CDATA[firefox]]></category>

		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://helephant.net/?p=427</guid>
		<description><![CDATA[
My find for today was a Firefox extension called Dust-Me Selectors from the SitePoint guys that scans a web site looking for unused selectors in the CSS.
It extracts the style references for the current page and then looks at the page to see where they are used. It can look at the current page or [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://helephant.net/wp-content/uploads/2008/11/dust.png"><img class="size-medium wp-image-541 alignright" title="dust me selector tool" src="http://helephant.net/wp-content/uploads/2008/11/dust-256x300.png" alt="" width="256" height="300" /></a></p>
<p>My find for today was a Firefox extension called <a href="https://addons.mozilla.org/en-US/firefox/addon/5392">Dust-Me Selectors</a> from the <a href="http://www.sitepoint.com/dustmeselectors/">SitePoint guys</a> that scans a web site looking for unused selectors in the CSS.</p>
<p>It extracts the style references for the current page and then looks at the page to see where they are used. It can look at the current page or you can set it up to spider your entire site.</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/GIb6pSF9iWc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2008/10/dust-me-selector-tool-for-finding-unused-css-selectors/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2008/10/dust-me-selector-tool-for-finding-unused-css-selectors/</feedburner:origLink></item>
		<item>
		<title>CSS3 box-sizing attribute</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/C1kwB8Yip1o/</link>
		<comments>http://helephant.com/2008/10/css3-box-sizing-attribute/#comments</comments>
		<pubDate>Mon, 20 Oct 2008 07:33:36 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[CSS]]></category>

		<category><![CDATA[bleedingedgeofweb]]></category>

		<category><![CDATA[borderbox]]></category>

		<category><![CDATA[boxmodel]]></category>

		<category><![CDATA[boxmodelswitch]]></category>

		<category><![CDATA[boxsizing]]></category>

		<category><![CDATA[contentbox]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[css3]]></category>

		<guid isPermaLink="false">http://helephant.net/?p=426</guid>
		<description><![CDATA[CSS3 is going to include a new attribute called box-sizing so we can choose whether the width set on an element will include borders and padding or whether borders and paddings will be added to the width.
The difference is basically the difference between the IE5 and W3C box models. The default will still be the [...]]]></description>
			<content:encoded><![CDATA[<p>CSS3 is going to include a new attribute called <a href="http://www.w3.org/TR/css3-ui/#box-sizing">box-sizing</a> so we can choose whether the width set on an element will include borders and padding or whether borders and paddings will be added to the width.</p>
<p>The difference is basically the difference between the IE5 and W3C <a href="http://www.addedbytes.com/css/box-model/">box models</a>. The default will still be the W3C way we&#8217;re all used to where the padding and borders will be added to the width, it&#8217;ll just be possible to opt into the other way when it makes things easier.</p>
<h2>How it works</h2>
<p>Set the box-sizing style to <strong>content-box</strong> to get the traditional W3C box model. In this case the total width of the element will be the width set on the element plus the width of the borders and padding. If you had an element with a width of 30 pixels and a border of one pixel, the total width of the element would be 32 pixels:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re0">#div1</span><span class="br0">&#123;</span> box-sizing<span class="sy0">:</span> content-box<span class="sy0">;</span><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>It can also be set to <strong>border-box</strong> to have borders and paddings included in the width. If you had an element with a width of 30 pixels and a border of one pixel the total width of the element would still be 30 pixels:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re0">#div2</span><span class="br0">&#123;</span> box-sizing<span class="sy0">:</span> border-box<span class="sy0">;</span> <span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Here&#8217;s how it would look in the browser. The top element has box-sizing set to content-box and the bottom has it set to border-box:</p>
<p><img src="/wp-content/uploads/2008/11/box-sizing-both.png" alt="content-box fits inside the parent container while border-box overlaps"/><br />
<a href="/wp-content/uploads/2008/11/box-sizing1.html">See code</a></p>
<h2>Why&#8217;s this useful?</h2>
<p>I&#8217;ve always found the way the browser works out dimensions (the CSS box model) by adding the borders to the width set on the box a little frustrating when working with percentage widths.</p>
<p>Imagine you&#8217;re creating a two column layout. The left column should be 30% and the right 70%:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re1">.left</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">float</span><span class="sy0">:</span> <span class="kw1">left</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3"><span class="nu0">30</span>%</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> pink<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">border</span><span class="sy0">:</span> <span class="re3">3px</span> <span class="kw2">red</span> <span class="kw2">dotted</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">150px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">.right</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">float</span><span class="sy0">:</span> <span class="kw1">left</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> lightgreen<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3"><span class="nu0">70</span>%</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">border</span><span class="sy0">:</span> <span class="re3">3px</span> <span class="kw2">green</span> <span class="kw2">dotted</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">150px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;div class=&quot;left&quot;&gt;content-box&lt;/div&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;div class=&quot;right&quot;&gt;box-sizing&lt;/div&gt;</div>
</li>
</ol>
</div>
<p>If you add a border to either box, the total with of the elements will be greater than 100% so the second box will be pushed onto the next line:</p>
<p><img src="/wp-content/uploads/2008/11/box-sizing-content.png" alt="" /></p>
<p>But if we switch the box-sizing mode to border-box, we can set a border and the box will still be exactly the width that we want:</p>
<p><img src="/wp-content/uploads/2008/11/box-sizing-border.png" alt="" /></p>
<h2>When&#8217;s it coming?</h2>
<p>When IE8 comes out this will be supported by all four of the big browsers.</p>
<p><strong>Safari</strong> - supported with -webkit-box-sizing since Safari 3.</p>
<p><strong>Opera</strong> - supported in the latest version of Opera (9.5)</p>
<p><strong>Firefox</strong> - supported with the -moz-box-sizing since Firefox 1.1.</p>
<p><strong>Internet Explorer</strong> - supported with -ms-box-sizing in the IE8 beta 1 and without the prefix in IE8 beta 2.</p>
<h2>More information</h2>
<ul>
<li><a href="http://idreamincode.co.uk/css/css3/the-css3-box-sizing-concept-a-solution-to-a-longstanding-problem">The CSS3 box-sizing concept</a> - an interesting write up about it from inside the W3C.</li>
<li><a href="http://www.quirksmode.org/css/box.html">Quirks mode</a> - nice pictures to explain the differences between the two model</li>
</ul>
<img src="http://feeds.feedburner.com/~r/helephant/~4/C1kwB8Yip1o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2008/10/css3-box-sizing-attribute/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2008/10/css3-box-sizing-attribute/</feedburner:origLink></item>
		<item>
		<title>Javascript closures</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/pJtylfNtPGw/</link>
		<comments>http://helephant.com/2008/10/javascript-closures/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 17:49:41 +0000</pubDate>
		<dc:creator>Helen</dc:creator>
		
		<category><![CDATA[Javascript]]></category>

		<category><![CDATA[Web development]]></category>

		<category><![CDATA[closures]]></category>

		<category><![CDATA[functional]]></category>

		<category><![CDATA[functionprogramming]]></category>

		<category><![CDATA[javascript]]></category>

		<category><![CDATA[memoryleak]]></category>

		<guid isPermaLink="false">http://helephant.net/?p=419</guid>
		<description><![CDATA[Javascript closures are a really powerful feature of the javascript language. Closures are created when a function that&#8217;s nested inside another function accesses a variable from its parent&#8217;s scope. This is really useful for passing state around your application when the inner function is called after the outer function has exited.
Javascript supports functions nested inside [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript closures are a really powerful feature of the javascript language. Closures are created when a function that&#8217;s nested inside another function accesses a variable from its parent&#8217;s scope. This is really useful for passing state around your application when the inner function is called after the outer function has exited.</p>
<h2>Javascript supports functions nested inside other functions</h2>
<p>Nested functions are possible because the function operator that makes it possible to create <a href="/2008/08/javascript-anonymous-functions/">anonymous functions</a> anywhere that it&#8217;s possible to have any other type of statement. Even if you&#8217;ve never heard of closures before, you&#8217;ve probably done this without thinking about it too much when you set up an event handler:</p>
<div class="geshi no javascript">
<div class="head">function myFunction(){</div>
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> button = document.<span class="me1">getElementById</span><span class="br0">&#40;</span><span class="st0">&quot;Button1&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; button.<span class="me1">addEventListener</span><span class="br0">&#40;</span><span class="st0">&quot;click&quot;</span>, <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;I am a function nested inside another function&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span>, <span class="kw2">false</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><a href="/wp-content/uploads/2008/11/nested.html">Complete example</a></p>
<h2>A closure is created when an inner function accesses variables from the outer function</h2>
<p>In javascript an inner function can access variables from the outer function&#8217;s scope. When this happens a closure is created. The closure is just a link from the inner function to the outer function from the time when the outer function exited. It&#8217;s created to save the state of the variables from the outer function so they are still available when the inner function is run.</p>
<p>The best way to understand this is to look at an example. Take a look at this piece of code which is very similar to the last example:</p>
<pre>function outerFunction(){
    var button = document.getElementById("Button1");
    var importantPieceOfState = "I love fish";
    // declare the inner event
    button.addEventListener("click", function()
    {
        alert(importantPieceOfState);
    }, false);
}</pre>
<p><a href="/wp-content/uploads/2008/11/closures.html">Complete example</a></p>
<p>When you run the button click handler code, the alert will say &#8220;I love fish&#8221; even though the importantPieceOfState variable is only declared in the outerFunction()&#8217;s scope.</p>
<p>Notice that importantPieceOfState isn&#8217;t declared anywhere inside the click event handler and that it isn&#8217;t a global variable. It is only declared as a local variable to the outerFunction() function. The variable is available because when we run outerFunction() the javascript engine notices that the click handler has a reference to one of the variables in outerFunction(). It creates a closure to save the current state of outerFunction() for when the click event is run. If the inner function didn&#8217;t access any of the outer function&#8217;s variables the closure would not be created.</p>
<p>All the variables from the outer function are available to the inner function. This includes the parameters. The only exception is any variables from the outer function that are overridden by variables from the inner function that have the same name.</p>
<h2>A new closure is created each time the function runs</h2>
<p>In the last example outerFunction() is only run once so only one closure is created. If we ran the outer function multiple times a new closure would be created each time.</p>
<p>Here&#8217;s another example where the outer function is called multiple times with different parameters:</p>
<pre>function setClickColor(button, color){
    // declare the inner event
    button.addEventListener("click", function()
    {
        button.style.backgroundColor = color;
    }, false);
}

window.onload = function(){
    setClickColor(document.getElementById("Button1"), "red");
    setClickColor(document.getElementById("Button2"), "blue");
}</pre>
<p><a href="/wp-content/uploads/2008/11/closures3.html">Complete example</a></p>
<p>Notice that the parameter has a different value for each inner function that is created. The color parameter is set to red for the red button click and blue for the blue button click. This happens because a new closure is created each time the function is run.</p>
<h2>Closures are created when the outer function exits</h2>
<p>The closure is actually created when the outer function exits, not when the inner function is created. This means the values of any variables will be saved as they are when the outer function exits.</p>
<p>This can be a bit confusing if you&#8217;re creating functions inside a loop. All of the functions you create will point to the same closure so the variable values will be the same for them all.</p>
<p>Imagine you had a list of buttons and you wanted to set up a click event for each. For some reason the order of the buttons is important so you want to access the button&#8217;s index in the array inside the loop:</p>
<pre>window.onload = function(){
    var buttons = ["Button1", "Button2"];
    for(var x=0; x&lt;buttons.length; x++)
    {
        var button = document.getElementById(buttons[x]);
        button.addEventListener("click", function()
        {
            alert("I am button " + x);
        }, false);
    }
}</pre>
<p><a href="/wp-content/uploads/2008/11/closures4.html">Complete example</a></p>
<p>Looking at the code you might expect x to be zero for the first button and one for the second button but it isn&#8217;t.  It&#8217;s three for both buttons because after the second event handler has been set up, the x variable is incremented to three and the loop&#8217;s condition fails. Then the function exits and the value of three is stored in the closure that&#8217;s used by both button click events.</p>
<h2>Closures reduce the need to pass around state</h2>
<p>Closures reduce the need to pass state around the application. The inner function has access to the variables in the outer function so there is no need to store the information somewhere that the inner function can get it.</p>
<p>This is important when the inner function will be called after the outer function has exited. The most common example of this is when the inner function is being used to handle an event. In this case you get no control over the arguments that are passed to the function so using a closure to keep track of state can be very convenient.</p>
<p>For example imagine you&#8217;re using the <a href="http://developer.mozilla.org/En/DOM/Window.setTimeout">setTimeout</a> function to do a mouseover effect where the element changes color when you mouse in for a few seconds and then changes back to the original color. You need to pass the setTimeout callback function the original color of the element but the IE version of setTimeout() method doesn&#8217;t allow you to pass any parameters to the callback function.</p>
<p>Closures make passing information like this simple. We just need to store the original background color in a variable in the outer function and then the inner function can just use the variable to reset the background color:</p>
<pre>var divs = document.getElementsByTagName("div");
for(var x=0; x</pre>
<p><a href="/wp-content/uploads/2008/11/closures2.html">Complete example</a></p>
<h2>Some things closures make possible</h2>
<p>Closures can be used to achieve some pretty neat stuff in javascript. Here are a link to a few really useful javascript patterns that use closures (please leave a comment if you know another interesting one):</p>
<ul>
<li><a href="http://yuiblog.com/blog/2007/06/12/module-pattern/">Module pattern</a> - the most flexible way to do namespaces for javascript.</li>
<li><a href="http://javascript.crockford.com/private.html">Private and protected members</a> - Douglas Crockford&#8217;s private and protected members for javascript objects.</li>
<li><a href="http://www.svendtofte.com/code/curried_javascript/">Curried javascript functions</a> - a <a href="http://en.wikipedia.org/wiki/Currying">functional programming technique</a>.</li>
</ul>
<h2>Potential problems</h2>
<p>Closures are a really useful tool to have in your javascript coding arsenal but you have to know about the two potential pitfalls. The first is that it makes it easier to introduce javascript memory leaks into your code. The second is that it can use a lot of memory if the outer function is called very often or the data that is saved is very large.</p>
<h3>Potential for memory leaks</h3>
<p>Unfortunately some browsers (IE in particular) have problems disposing of DOM elements and javascript objects that have a circular reference between them. This can be a big problem because the affected objects will stay in memory until the browser is restarted, even if another page is loaded. This isn&#8217;t a problem for closures exclusively but closures can sometimes make the circular references hard to see.</p>
<p>To solve this you just need to break all the links from DOM to javascript when the page unloads and then the circular references are broken. This will mean unhooking any DOM events that have been set up during the page&#8217;s life and setting any attributes of the DOM elements that point to javascript objects to null. It&#8217;s really important to do this even if you&#8217;re not using closures because you&#8217;re really likely to run into memory leaks if you don&#8217;t.</p>
<p>Most javascript frameworks will automatically unhook all of the event handlers if you register the events using the framework&#8217;s methods. In the ASP.NET Ajax framework you need to make sure that you call <a href="http://asp.net/ajax/documentation/live/clientreference/Global/ClearHandlersShortcutMethod.aspx">$clearHandlers()</a> on any html element to which you added a handler.</p>
<p>Javascript memory leaks are my least favourite type of webpage program to debug because it can be really hard to track down what&#8217;s leaking. However there are a few really great articles you can read to understand what happens so you can prevent your code ever leaking in the first place:</p>
<ul>
<li><a href="http://javascript.crockford.com/memory/leak.html">Javascript memory leaks</a> - why memory leaks happen and how to break the circular references.</li>
<li><a href="http://blog.grimpoteuthis.org/2005/01/dhtml-leaks-like-sieve.html">DHTML Leaks Like a Sieve</a> - a good general explanation of the problem</li>
<li><a href="http://www.quirksmode.org/blog/archives/2005/10/memory_leaks_li.html#more">QuirksBlog memory leak links</a> - links to a heap of useful articles about memory leaks</li>
</ul>
<h3>Could potentially use a lot of memory</h3>
<p>When a closure is created the execution context of the current function call is saved with a reference to all the variables in the function&#8217;s scope. This can use a lot of memory if a lot of frames get saved or if each execution context is very large.</p>
<p>Outer functions that get called a lot of time aren&#8217;t good candidates to be used for closures because each time the function is called a new closure will be saved. The inner function can be called as many times as you want. It&#8217;s only when the outer function gets called that a new closure gets created.</p>
<p>It could also be a problem if the amount of data inside the outer function are very large. If you had a ten thousand character string in the outer function it probably would not be a good candidate to be used for closures. Again this only affects the outer function. The inner function does not affect the amount of data to be saved.</p>
<p>In most cases using closures will be fine, but if you do find that your application is using more memory than you&#8217;d like closures are a possible cause of the problem.</p>
<h2>More information</h2>
<p>Closures are a bit of a tricky topic to get your head around if you&#8217;ve never seen them before but there are a few really great resources about them available to help.</p>
<ul>
<li><a href="http://ejohn.org/apps/learn/#48">Closures tutorial</a> - John Resig (of JQuery fame) has written a helpful interactive tutorial for helping people understand how closures work.</li>
<li><a href="http://blog.morrisjohns.com/javascript_closures_for_dummies">Javascript closures for dummies</a> is a fantastic reference that takes you through a heap of different code examples about closures and explains the most important concepts.</li>
<li><a href="http://www.jibbering.com/faq/faq_notes/closures.html">Javascript Closures</a> is the complete reference on closures. It goes into very extensive technical detail. It&#8217;s not the easiest read but it explains a lot of useful things about how closures and javascript functions in general really work.</li>
</ul>
<h2>What&#8217;s next?</h2>
<p>This article is part of a set of related posts about <a href="/2008/08/building-objects-with-javascript/">using javascript objects</a>. This article is part of <a href="/2008/08/how-javascript-objects-work/">how javascript objects work</a>.</p>
<p>Although constructor functions look a lot like classes, javascript does not have a class based object system like C# or Java. Instead it has a <a href="/2009/01/javascript-object-prototype/">prototype based</a> object system.</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/pJtylfNtPGw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2008/10/javascript-closures/feed/</wfw:commentRss>
		<feedburner:origLink>http://helephant.com/2008/10/javascript-closures/</feedburner:origLink></item>
	</channel>
</rss>
