<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>The Coding Bug</title>
    <description>Personal web development blog covering ASP.NET MVC, jQuery, Chrome Extensions and more.</description>
    <link>http://thecodingbug.com/Blog/</link>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/TheCodingBug" /><feedburner:info uri="thecodingbug" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
      <title>Better URLs for Scandinavian letters in N2CMS</title>
      <description>&lt;p&gt;In &lt;a title="Lightweight CMS framework" href="http://n2cms.com/" target="_blank"&gt;N2CMS&lt;/a&gt; the default behavior when creating a page containing ‘Å’ or ‘Ö’ in the URL is to replace it with ‘Ae’ and ‘Oe’. I find this makes less readable URLs, and I believe people are more used to read URLs where you replace it with a single letter, e.g. ‘Å’ to ‘A’.&lt;/p&gt;  &lt;p&gt;Example for page title “Räksmörgås”:    &lt;br&gt;Default: &lt;code&gt;raeksmoergas/&lt;/code&gt;    &lt;br&gt;Wanted: &lt;code&gt;raksmorgas/&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;To change this &lt;a title="Source code for default values set by PatternValueCollection" href="http://api.n2cms.com/_pattern_value_collection_8cs_source.html" target="_blank"&gt;default behavior&lt;/a&gt; in N2CMS you need to add this configuration to Web.config:&lt;/p&gt;  &lt;pre class="code-block"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;n2&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;edit&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;nameEditor&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;replacements&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;remove&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;smallAE&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;remove&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;capitalAE&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;remove&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;smallOE&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;remove&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;capitalOE&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;remove&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;theRest&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&#xD;
 &#xD;
&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;smallAE-new&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;pattern&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;[æä]&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;a&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; /&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;capitalAE-new&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;pattern&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;[ÆÄ]&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;A&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; /&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;smallOE-new&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;pattern&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;[ö]&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;o&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; /&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;capitalOE-new&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;pattern&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;[Ö]&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;O&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt; /&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;add&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;name&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;theRest-new&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;pattern&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;[^. a-zA-Z0-9_-]&lt;/span&gt;&amp;quot;&lt;span style="color: blue"&gt;&amp;#160;&lt;/span&gt;&lt;span style="color: red"&gt;value&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;&amp;quot;&amp;quot;&lt;span style="color: blue"&gt; /&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;replacements&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;nameEditor&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;#160; &amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;edit&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&#xD;
&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;n2&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/etZMCY-A7VY" height="1" width="1"/&gt;</description>
      <category>N2CMS</category>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/etZMCY-A7VY/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2012/3/4/better-urls-for-scandinavian-letters-in-n2cms/</guid>
      <pubDate>Sun, 04 Mar 2012 17:25:29 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2012/3/4/better-urls-for-scandinavian-letters-in-n2cms/</feedburner:origLink></item>
    <item>
      <title>Error when trying to Add-Migration in EF Code First Migrations–Alpha 3</title>
      <description>&lt;p&gt;Getting an exception like the below one when trying to add a migration with the shiny new Alpha 3 of migrations?&lt;/p&gt;  &lt;pre&gt;&lt;code&gt;Add-Migration : Could not load type 'System.Data.Entity.Infrastructure.DbContextInfo' &#xD;
	from assembly 'EntityFramework, Version=4.1.0.0, &#xD;
	Culture=neutral, PublicKeyToken=b77a5c561934e089'.&#xD;
&#xD;
At line:1 char:16&#xD;
&#xD;
+ add-migration &amp;lt;&amp;lt;&amp;lt;&amp;lt;&#xD;
   + CategoryInfo          : NotSpecified: (:) [Add-Migration], TypeLoadException&#xD;
   + FullyQualifiedErrorId : System.TypeLoadException,System.Data.Entity.Migrations.AddMigrationCommand&lt;/code&gt;&lt;/pre&gt;&#xD;
&#xD;
&lt;p&gt;The solution is to &lt;strong&gt;uninstall Microsoft ADO.NET Entity Framework 4.1 RC. &lt;/strong&gt;To be on safe side, restart Visual Studio after the uninstallation.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Read more about migrations: &lt;a href="http://blogs.msdn.com/b/adonet/archive/2011/09/21/code-first-migrations-alpha-3-released.aspx" target="_blank"&gt;Code First Migrations: Alpha 3 Released&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/b/adonet/archive/2011/09/21/code-first-migrations-alpha-3-no-magic-walkthrough.aspx" target="_blank"&gt;Code First Migrations: Alpha 3 ‘No-Magic’ Walkthrough&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/DCE7ODqG_v4" height="1" width="1"/&gt;</description>
      <category>.net</category>
      <category>Code First</category>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/DCE7ODqG_v4/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2011/9/26/error-when-trying-to-add-migration-in-ef-code-first-migrations-alpha-3/</guid>
      <pubDate>Mon, 26 Sep 2011 20:57:47 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2011/9/26/error-when-trying-to-add-migration-in-ef-code-first-migrations-alpha-3/</feedburner:origLink></item>
    <item>
      <title>Late to the Github Party and How I Got There</title>
      <description>&lt;p&gt;Right, so I was late but I am there now – in Github. I spent a few hours yesterday to setup everything and while it took a bit longer than with Subversion I still think it was easier than expected.&lt;/p&gt;  &lt;p&gt;This post is for other Windows users who want a short overview of what you need to do to become a Githubber.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://code.google.com/p/gitextensions/" target="_blank"&gt;&lt;img title="image" border="0" alt="image" align="right" src="http://assets.codingbug.com/uploads/Windows-Live-Writer/f1126bcad7b8_88DF/image_3.png" width="226" height="323"&gt;&lt;/a&gt;Get an account at &lt;a href="http://github.com" target="_blank"&gt;Github&lt;/a&gt;.       &lt;br&gt;The reason we do this first is because Github have a really good guide for beginners.&amp;#160; &lt;/li&gt;    &lt;li&gt;Download &lt;a href="http://code.google.com/p/msysgit/downloads/list?can=3" target="_blank"&gt;Git for Windows&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;Follow the &lt;a href="http://help.github.com/win-set-up-git/" target="_blank"&gt;guide at Github&lt;/a&gt; (read both “Set Up Git” and “Create A Repo”). &lt;/li&gt;    &lt;li&gt;You should now have submitted your first commit to your repo through the command line or the Git GUI. Congratulations! &lt;/li&gt;    &lt;li&gt;If you’re like me, you don’t like the cmd-way (I really tried to!) and want something visually appealing instead. I found the &lt;a href="http://code.google.com/p/gitextensions/" target="_blank"&gt;Git Extensions project&lt;/a&gt; which suited me well. Besides giving you a complete overview of the repo, it also integrates with VS2010 by adding a “Git” menu. Handy! &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;That’s actually all I had to do. The only problem I had was with Git Extensions because it used PuTTY for SSH while the guide used OpenSSH. To fix it I had to generate a new SSH key (public and private) in PuTTY and add the public key to my Github account. Apparently PuTTY is more suited for Windows than OpenSSH is.&lt;/p&gt;  &lt;h3&gt;Git tips for Visual Studio&lt;/h3&gt;  &lt;p&gt;&lt;strong&gt;README      &lt;br&gt;&lt;/strong&gt;Name the README file with the “.markdown” file extension and use VS extension “&lt;a href="http://visualstudiogallery.msdn.microsoft.com/0855e23e-4c4c-4c82-8b39-24ab5c5a7f79" target="_blank"&gt;Markdown Mode&lt;/a&gt;” to edit it.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;.gitignore      &lt;br&gt;&lt;/strong&gt;Create a new file called “.gitignore” in the root of the repository and fill it will directories/files that you don’t want to stay in the repository. Following is a .gitignore file which filters Visual Studio and ReSharper files:&lt;/p&gt;  &lt;pre&gt;bin &#xD;
obj &#xD;
*.suo &#xD;
*.user &#xD;
*.csproj.user &#xD;
*.cache &#xD;
*.resharper.user &#xD;
_ReSharper* &#xD;
*.sln.docstates*&lt;/pre&gt;&#xD;
&#xD;
&lt;h3&gt;Summary&lt;/h3&gt;&#xD;
&#xD;
&lt;p&gt;After all, Git wasn’t as scary as I had believed and the Github website makes it a really nice experience with its beautiful UI and social features.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;So what are you waiting for? Go follow &lt;a title="Follow codingbug on Github" href="https://github.com/codingbug" target="_blank"&gt;me on Github&lt;/a&gt; (or watch some &lt;a href="https://github.com/popular/watched" target="_blank"&gt;interesting projects&lt;/a&gt;)!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/4tger6og_6k" height="1" width="1"/&gt;</description>
      <category>Visual Studio</category>
      <category>Github</category>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/4tger6og_6k/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2011/8/1/late-to-the-github-party-and-how-i-got-there/</guid>
      <pubDate>Mon, 01 Aug 2011 07:30:00 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2011/8/1/late-to-the-github-party-and-how-i-got-there/</feedburner:origLink></item>
    <item>
      <title>Displaying Assembly Version in Windows Explorer</title>
      <description>&lt;p&gt;&lt;a href="http://assets.codingbug.com/uploads/Windows-Live-Writer/e54982d33c14_A255/fileversion.png"&gt;&lt;img title="fileversion" border="0" alt="fileversion" align="right" src="http://assets.codingbug.com/uploads/Windows-Live-Writer/e54982d33c14_A255/fileversion_thumb.png" width="240" height="133"&gt;&lt;/a&gt;I have been working a lot with upgrading assemblies to newer versions and debugging why things does not work. When doing this you often have to check which version you currently have in your “bin” folder. This takes quite a lot of time as you have to check properties of each file (or hover of the file and wait for the tooltip) to see the assembly version. It is hard to get a quick glance over all your dll versions.&lt;/p&gt;  &lt;p&gt;What I did was to add a new column to Windows Explorer which shows the file version. Follow the steps below to show file version in Windows 7:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font color="#3f3f3f" face="Trebuchet MS"&gt;In the bin folder, right click on the column row and select “More…”.&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font color="#3f3f3f" face="Trebuchet MS"&gt;Search for and mark the item called “File version” and click OK.&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font color="#3f3f3f" face="Trebuchet MS"&gt;You should now see a column with the version number!&lt;/font&gt;&lt;/li&gt; &lt;/ol&gt;&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/ZDYwByQTygg" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/ZDYwByQTygg/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2010/11/26/displaying-assembly-version-in-windows-explorer/</guid>
      <pubDate>Fri, 26 Nov 2010 14:30:39 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2010/11/26/displaying-assembly-version-in-windows-explorer/</feedburner:origLink></item>
    <item>
      <title>Notes from Øredev 2010</title>
      <description>&lt;p&gt;Time flies – the Øredev week is already over and I’m back at the office. The conference was really great. Reaching above my expectations. It was of course great to learn a lot of new stuff, but what I think was the best part about the conference is that it gives you a lot of inspiration to create applications, try out new things and walk that extra mile to make your application more maintainable and tested. &lt;/p&gt;  &lt;p&gt;The sessions were divided in different areas, e.g. .NET, web development, agile and smart phones. It was never hard to find a session I wanted to go to. I, however, recommend to create your own schedule beforehand as it’s really handy to have with you when you’re at the conference running between sessions.&lt;/p&gt;  &lt;p&gt;During the sessions I tried to write notes about the things I found most interesting, but it was hard to keep up with both listening and taking notes. Following is notes I wrote down from some of the sessions I attended.&lt;/p&gt;  &lt;h4&gt;Patterns for Building Internal DSL's in C# 3.0&lt;/h4&gt;  &lt;p&gt;In this session Jeremy D. Miller talked about &lt;a href="http://www.hanselman.com/blog/TheWeeklySourceCode14FluentInterfaceEdition.aspx" target="_blank"&gt;Fluent Interfaces&lt;/a&gt; which are handy in certain APIs, like a Twitter client API. &lt;/p&gt;  &lt;p&gt;When creating such interfaces you should think about:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Don’t try to make everything grammatically correct. Small and tidy method names are better and easier to understand. &lt;/li&gt;    &lt;li&gt;You should limit the possible choices in the API to guide user to the right methods. This can be done by using Interfaces instead of returning the same object over and over again. &lt;/li&gt;    &lt;li&gt;You should keep the chaining within 3 chain calls. &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Better Practices for Building Fast Web Apps&lt;/h4&gt;  &lt;p&gt;This was quite an interesting talk as it covered lots of tools I hadn’t heard of before. Giorgio Sardo mention tools you can use to increase the performance of your sites. Like &lt;a href="http://spriteme.org/" target="_blank"&gt;using sprites&lt;/a&gt;, &lt;a href="http://blogs.msdn.com/b/ie/archive/2010/03/03/css-crunch-new-ie-extension-for-developers.aspx" target="_blank"&gt;finding out not used CSS styles&lt;/a&gt; and a tool called &lt;a href="http://research.microsoft.com/en-us/projects/doloto/" target="_blank"&gt;Doloto&lt;/a&gt; that converts your existing scripts to be lazy loaded instead.&lt;/p&gt;  &lt;p&gt;The tip I liked especially much was when he mention about a new API called &lt;a href="https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html" target="_blank"&gt;Web Timing API&lt;/a&gt; that browsers are starting to implement. It can be used to find lots of details about how fast your site has loaded. I knew about this API before the talk, but what caught my attention was when gave the smart tip of actually sending this data (serialized JavaScript object) to the server to get free profiling information from your users. How cool isn’t that!&lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2b0ea69a-6612-4b05-90e8-ff5c8a8af48c" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;&lt;span style="color:#006400"&gt;//IE&lt;/span&gt;&lt;br&gt; window.msPerfomance&lt;br&gt; &lt;br&gt; &lt;span style="color:#006400"&gt;//Webkit&lt;/span&gt;&lt;br&gt; window.webkitPerformance&lt;/div&gt; &lt;/div&gt;  &lt;h4&gt;   &lt;br&gt;CSS3&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://assets.codingbug.com/uploads/Windows-Live-Writer/ff310b3415ea_11D35/IMAG0231_2.jpg"&gt;&lt;img title="IMAG0231" border="0" alt="CSS3 with Jonathan Snook" align="right" src="http://assets.codingbug.com/uploads/Windows-Live-Writer/ff310b3415ea_11D35/IMAG0231_thumb.jpg" width="240" height="160"&gt;&lt;/a&gt;Jonathan Snook talked about all the new fun things in CSS3, like animations, transitions, border-radius and shadows of all kind, etc. He also went through all different browsers and what they currently support.&lt;/p&gt;  &lt;p&gt;Until CSS3 is ready it has to go through these states: Working Draft, Last Call, Candidate Recommendation, Proposed Recommendation&lt;font color="#333333" face="Helvetica"&gt; and finally&lt;/font&gt; Recommendation. Note that each module in CSS3 has its own state, and not one all together. You can see in &lt;a href="http://www.w3.org/Style/CSS/current-work" target="_blank"&gt;which state each module is in&lt;/a&gt; at the W3C site.&lt;/p&gt;  &lt;p&gt;Good links shared by Snook:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;CSS3 slideshow in CSS3: &lt;a href="http://leaverou.me/ft2010/"&gt;http://leaverou.me/ft2010/&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Find out about browser support: &lt;a href="http://caniuse.com/"&gt;http://caniuse.com/&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Detect which features are available in the browser: &lt;a href="http://www.modernizr.com/"&gt;http://www.modernizr.com/&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;ASP.NET MVC 3&lt;/h4&gt;  &lt;p&gt;A few days before the conference Scott Gu (and all other the bloggers) announced that ASP.NET MVC 3 Release Candidate was released. This is great news as it means there is only bug-fixing left before we get the final version. Brad Wilson had this talk and he did it great! He talked about the new Razor syntax, the new package manager NuGet and some new features in MVC 3.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;font color="#3f3f3f" face="Trebuchet MS"&gt;Partial caching in child actions.&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font color="#3f3f3f" face="Trebuchet MS"&gt;Unobtrusive JavaScript validation.&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font color="#3f3f3f" face="Trebuchet MS"&gt;Razor syntax highlighting in Visual Studio.&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font color="#3f3f3f" face="Trebuchet MS"&gt;A way to turn of session for a controller (&lt;code&gt;[ControllerSessionState()]&lt;/code&gt;).&lt;/font&gt; &lt;/li&gt;    &lt;li&gt;&lt;font color="#3f3f3f" face="Trebuchet MS"&gt;And lots more…&lt;/font&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;“Abusing C#” and “C#'s Greatest Mistakes”&lt;/h4&gt;  &lt;p&gt;&lt;a href="http://assets.codingbug.com/uploads/Windows-Live-Writer/ff310b3415ea_11D35/5173237658_f5dda6b7a5_z_2.jpg"&gt;&lt;img title="Jon Skeet abusing C#" border="0" alt="Jon Skeet abusing C#" align="right" src="http://assets.codingbug.com/uploads/Windows-Live-Writer/ff310b3415ea_11D35/5173237658_f5dda6b7a5_z_thumb.jpg" width="240" height="180"&gt;&lt;/a&gt;These two talks was given by Jon Skeet, the man, the myth, the legend in C#. It was a really interesting talk covering lots of different ways to hack around in C# in ways you maybe shouldn’t do in production mode. &lt;/p&gt;  &lt;p&gt;The two talks were very similar in the way they were presented. They both had no slides and only covered Skeet going through examples of areas the audience wanted to learn more about. It really felt like we could fill a whole conference with only Jon Skeet talking about C# (I would totally go on it).&lt;/p&gt;  &lt;hr&gt;Now I’m eagerly waiting for Øredev to publish the videos of all the other sessions I didn’t attend to. It seems they will be published on &lt;a href="http://vimeo.com/user2649908/videos" target="_blank"&gt;Vimeo&lt;/a&gt;. Read more details about the other sessions at my colleague’s blog &lt;a href="http://blog.dileno.com/archive/201011/oredev-2010--last-day/" target="_blank"&gt;Dileno&lt;/a&gt;. See you at the next Øredev!&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/0CpSEcr-p7o" height="1" width="1"/&gt;</description>
      <category>Øredev</category>
      <category>Conference</category>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/0CpSEcr-p7o/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2010/11/16/notes-from-oredev-2010/</guid>
      <pubDate>Tue, 16 Nov 2010 08:00:00 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2010/11/16/notes-from-oredev-2010/</feedburner:origLink></item>
    <item>
      <title>Schedule for Øredev 2010</title>
      <description>&lt;p&gt;The yearly &lt;a href="http://oredev.org/2010" target="_blank"&gt;Øredev Developer Conference&lt;/a&gt; is now closing in, and I’m really excited to be able to participated this year. I’m leaving Wednesday and getting there around 10-11 AM which means I will unfortunately miss a few sessions in the morning but I’m sure the other sessions will weight up.&lt;/p&gt;  &lt;p&gt;I look forward to learning a lot of new interesting techniques and patterns, especially in sessions covering .NET, web app development, HTML5/CSS3 and nosql. It will also be great to see people like Jon Skeet, Brad Wilson, Jeremy D. Miller and Jonathan Snook “in real life”. Makes me wonder if &lt;a href="http://stackoverflow.com/users/22656/jon-skeet" target="_blank"&gt;Jon Skeet&lt;/a&gt; will even answer questions now when he can’t get any up-votes for it?&lt;/p&gt;  &lt;p&gt;The sessions I will attend to are:&lt;/p&gt;  &lt;h4&gt;Wednesday&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;11:20: ASP.NET Web Matrix and Web Pages, &lt;em&gt;Brad Wilson&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;13:10: &lt;font color="#a5a5a5"&gt;★&lt;/font&gt; Patterns for Building Internal DSL's in C# 3.0, &lt;em&gt;Jeremy D. Miller&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;14:15: Better Practices for Building Fast Web Apps, &lt;em&gt;Giorgio Sardo&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;15:35: Automated Testing of Web Applications, &lt;em&gt;Jeremy D. Miller&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;16:40: &lt;font color="#a5a5a5"&gt;★&lt;/font&gt; CSS3, &lt;em&gt;Jonathan Snook&lt;/em&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Thursday&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;10:15: &lt;font color="#a5a5a5"&gt;★&lt;/font&gt; Higher-Order JavaScript, &lt;em&gt;Giles Bowkett&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;11:20: Exploring Windows Phone Dev, &lt;em&gt;Jeff Wilcox&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;13:10: &lt;font color="#a5a5a5"&gt;★&lt;/font&gt; CouchDB for .NET Developers, &lt;em&gt;Hadi Hariri&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;14:15: &lt;font color="#a5a5a5"&gt;★&lt;/font&gt; ASP.NET MVC 3, &lt;em&gt;Brad Wilson&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;15:35: &lt;font color="#a5a5a5"&gt;★&lt;/font&gt; Abusing C#, &lt;em&gt;Jon Skeet&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;16:40: Compositional Design with Responsibility Driven Design, &lt;em&gt;Jeremy D. Miller&lt;/em&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Friday&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;10:15: My last 30 failures, &lt;em&gt;Ted Valentin&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;11:20: &lt;font color="#a5a5a5"&gt;★&lt;/font&gt; C#'s Greatest Mistakes, &lt;em&gt;Jon Skeet&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;13:10: &lt;font color="#a5a5a5"&gt;★&lt;/font&gt; 19 1/2 Things to Make You a Better Object Oriented Programmer, &lt;em&gt;Greg Young&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;14:15: &lt;font color="#a5a5a5"&gt;★&lt;/font&gt; Top 20 tools and tips that make me a better developer, &lt;em&gt;Roy Osherove&lt;/em&gt; &lt;/li&gt;    &lt;li&gt;15:35: &lt;font color="#a5a5a5"&gt;★&lt;/font&gt; Pluggable web applications, &lt;em&gt;Rob Ashton&lt;/em&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;font color="#a5a5a5"&gt;★&lt;/font&gt; = me like.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/NjTM5wyaHFE" height="1" width="1"/&gt;</description>
      <category>Øredev</category>
      <category>Conference</category>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/NjTM5wyaHFE/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2010/11/8/schedule-for-oredev-2010/</guid>
      <pubDate>Mon, 08 Nov 2010 21:57:33 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2010/11/8/schedule-for-oredev-2010/</feedburner:origLink></item>
    <item>
      <title>“Key has already been added” exception with PageTypeBuilder</title>
      <description>&lt;p&gt;This is one of those exceptions you get and you know you have had them before but never remember the solution, and googling them doesn’t give you any answers. Time to fix that!&lt;/p&gt;  &lt;h4&gt;Background&lt;/h4&gt;  &lt;p&gt;I was in the process of creating lots of new page-types for a new EPiServer&amp;#160; website and suddenly it threw an exception after building and running the site. The exception message I got was “An item with the same key has already been added.” with the following Stack Trace:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;b&gt;[ArgumentException: An item with the same key has already been added.]&lt;/b&gt;&#xD;
   System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +56&#xD;
   System.Collections.Generic.Dictionary`2.&lt;b&gt;Insert&lt;/b&gt;(TKey key, TValue value, Boolean add) +10290303&#xD;
   System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) +12&#xD;
   PageTypeBuilder.PageTypeResolver.&lt;b&gt;AddPageType&lt;/b&gt;(Int32 pageTypeID, Type pageTypeType) +52&#xD;
   PageTypeBuilder.Synchronization.PageTypeSynchronizer.AddPageTypesToResolver(List`1 pageTypeDefinitions) +159&lt;/pre&gt;&#xD;
&#xD;
&lt;p&gt;What we can understand from the above Stack Trace is that when PageTypeBuilder adds a new page-type to the dictionary it fails because another item with the same key already exists. My colleagues and I were determined this key must be the page-type GUID that you specify in the attribute of a page-type. I opened the database and deleted all page-types directly, and then changed the GUIDs in my classes. This has to work – but it did not.&lt;/p&gt;&#xD;
&#xD;
&lt;h4&gt;Solution&lt;/h4&gt;&#xD;
&#xD;
&lt;p&gt;I gave up and continued working with my page-types. After a few minutes I found a page-type with an incorrect name – it was a duplicate of another page-type! I changed it to the right name and ran my site. Everything worked! I had been affected by the “copy-paste error”.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;To sum it up: &lt;strong&gt;Every page-type must have a unique Name property or else it’ll fail in runtime.&lt;/strong&gt;&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;It would be nice if PageTypeBuilder threw a friendly exception if the key already exists. If the exception message also mention which page-type (by ID or name) it would be really easy to find and solve the problem.&lt;/p&gt;&#xD;
&#xD;
&lt;p&gt;Maybe it’s time to submit a patch to the PageTypeBuilder project?&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/VIooklZZkik" height="1" width="1"/&gt;</description>
      <category>PageTypeBuilder</category>
      <category>ASP.NET</category>
      <category>EPiServer</category>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/VIooklZZkik/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2010/10/7/key-has-already-been-added-exception-with-pagetypebuilder/</guid>
      <pubDate>Thu, 07 Oct 2010 07:50:56 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2010/10/7/key-has-already-been-added-exception-with-pagetypebuilder/</feedburner:origLink></item>
    <item>
      <title>Import Namespaces for Razor Views</title>
      <description>&lt;p&gt;Previously when developing with the WebForms view engine we could use the Web.config file to import namespaces where we stored our extension methods or models. They would then be available to all our views without having to explicitly declare them in each view. &lt;/p&gt;  &lt;p&gt;In Razor this is no longer possible due to how it’s built, which is why we have to manually register them in the Application_Start event.&lt;/p&gt;  &lt;p&gt;To do this begin with opening Global.asax and create a new method called RegisterGlobalImports, and call it from the Application_Start method. In the newly created method you add all the namespaces you wish to have in your view by calling AddGlobalImport on CodeGeneratorSettings.&lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:209f1581-7dc3-4101-82fb-9c9076c72a0c" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;static&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; RegisterGlobalImports() {&lt;br&gt;     &lt;span style="color:#2b91af"&gt;CodeGeneratorSettings&lt;/span&gt;.AddGlobalImport(&lt;span style="color:#a31515"&gt;&amp;quot;MvcApplicationRazor.Core.Extensions&amp;quot;&lt;/span&gt;);&lt;br&gt;     &lt;span style="color:#2b91af"&gt;CodeGeneratorSettings&lt;/span&gt;.AddGlobalImport(&lt;span style="color:#a31515"&gt;&amp;quot;MvcApplicationRazor.Core.Models&amp;quot;&lt;/span&gt;);&lt;br&gt; }&lt;br&gt; &lt;br&gt; &lt;span style="color:#0000ff"&gt;protected&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Application_Start() {&lt;br&gt;     RegisterGlobalImports();&lt;br&gt;     &lt;br&gt;     &lt;span style="color:#2b91af"&gt;AreaRegistration&lt;/span&gt;.RegisterAllAreas();            &lt;br&gt;     RegisterRoutes(&lt;span style="color:#2b91af"&gt;RouteTable&lt;/span&gt;.Routes);&lt;br&gt; }&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;I usually register extension methods, that should be available in the view, and models so I won’t have to type namespaces over and over again. &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/pwKNVI_la4A" height="1" width="1"/&gt;</description>
      <category>ASP.NET MVC</category>
      <category>Razor</category>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/pwKNVI_la4A/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2010/7/28/import-namespaces-for-razor-views/</guid>
      <pubDate>Wed, 28 Jul 2010 21:43:02 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2010/7/28/import-namespaces-for-razor-views/</feedburner:origLink></item>
    <item>
      <title>Getting HTML Colorization with Razor View Engine</title>
      <description>&lt;p&gt;&lt;a href="http://assets.codingbug.com/uploads/WindowsLiveWriter/546f2e76b6d9_1427D/image_5.png"&gt;&lt;img class="wlDisabledImage" title="image" border="0" alt="image" align="right" src="http://assets.codingbug.com/uploads/WindowsLiveWriter/546f2e76b6d9_1427D/image_thumb_1.png" width="240" height="159"&gt;&lt;/a&gt;Today the Gu announced the &lt;a href="http://weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx" target="_blank"&gt;first preview of ASP.NET MVC 3&lt;/a&gt;, which included the new Razor view engine. I’ve been really excited about it as I feel it makes our views a lot prettier than before with Web Forms view engine. It will also be a lot quicker and smoother to type without all those messy &lt;code&gt;&amp;lt;%&lt;/code&gt;-characters.&lt;/p&gt;  &lt;p&gt;To the point! I am currently upgrading an existing site to use MVC 3 and Razor. However in this first preview of MVC 3 we won’t have any File Colorization or IntelliSense in .cshtml files. This means it will look like we’re editing in Notepad. It got me wondering if there was a way to at least get some colorization, more specifically HTML colorization. I wandered around in the options of VS2010, and eventually found the place where I could map an extension to a different colorization.&lt;/p&gt;  &lt;p&gt;This is how you get HTML colorization in &lt;code&gt;.cshtml&lt;/code&gt; files:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font color="#3f3f3f" face="Trebuchet MS"&gt;Open Tools menu.&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font color="#3f3f3f" face="Trebuchet MS"&gt;Choose Options…&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font color="#3f3f3f" face="Trebuchet MS"&gt;Go to Text Editor, and third choice; File Extension.&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font color="#3f3f3f" face="Trebuchet MS"&gt;Enter &lt;em&gt;cshtml&lt;/em&gt; as Extension and choose HTML Editor in the dropdown.&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font color="#3f3f3f" face="Trebuchet MS"&gt;Click Add and OK. Now try to open a .cshtml file – you should get HTML colorization.&lt;/font&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p class="note"&gt;Remember to remove this setting when VS2010 officially gets Razor colorization and IntelliSense.   &lt;br&gt;&lt;/p&gt;  &lt;p&gt;That’s it. Hopefully it will be a little bit easier on your eyes.   &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/bJLCgAVebtE" height="1" width="1"/&gt;</description>
      <category>ASP.NET MVC</category>
      <category>Visual Studio</category>
      <category>Razor</category>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/bJLCgAVebtE/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2010/7/27/getting-html-colorization-with-razor-view-engine/</guid>
      <pubDate>Tue, 27 Jul 2010 23:21:09 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2010/7/27/getting-html-colorization-with-razor-view-engine/</feedburner:origLink></item>
    <item>
      <title>How to Use the Omnibox API in Google Chrome</title>
      <description>&lt;p&gt;The Omnibox API in Chrome is currently an experimental API, which means you can’t upload the extension to the gallery if your using it. Though, it works very well for local testing, and that is what we are going to do now.&lt;/p&gt;  &lt;p&gt;When I first heard there was going to be an Omnibox API I figured it would let us hook in on every change in the address bar and then add my own results to it. However, this isn’t how the API was implemented, and after reading Aaron’s comment about why, I understand and believe it’s the right way to go.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;[…] The omnibox has a very small results space. I'm hesitant to get into a      &lt;br&gt;situation where a bunch of extensions are fighting to make their results the most relevant. […]&lt;/p&gt;   &lt;cite&gt;― &lt;a href="http://code.google.com/p/chromium/issues/detail?id=38884#c7" target="_blank"&gt;Aaron Boodman&lt;/a&gt;&lt;/cite&gt;&lt;/blockquote&gt;  &lt;p&gt;In fact the only difference from how I thought it would work is that each extension sets a keyword (like search engines) in the manifest (&lt;code&gt;omnibox_keyword&lt;/code&gt;) and this is the word the extension will respond to in the Omnibox. This means that, like Aaron said, we won’t have to fight with other extensions about space – we have our own reserved space in the results list. Smart!&lt;/p&gt;  &lt;h3&gt;How to Use&lt;/h3&gt;  &lt;p&gt;Like mentioned earlier, you need to first add a setting to the manifest.json file where you specify the keyword the Omnibox will respond to. This will look identical to how the custom search engines behave in the Omnibox&lt;/p&gt;  &lt;p&gt;&lt;img class="wlDisabledImage" title="omnibox-1" alt="omnibox-1" src="http://assets.codingbug.com/uploads/WindowsLiveWriter/f1ca58cf933f_10CA3/omnibox-1_5eeadf4f-f553-4e2f-be08-891c369fd0d7.png" width="608" height="64"&gt; &lt;/p&gt;  &lt;p&gt;Currently the Omnibox API consists of four events:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;font color="#a5a5a5"&gt;chrome.experimental.omnibox.&lt;/font&gt;onInputStarted &lt;/li&gt;    &lt;li&gt;&lt;font color="#a5a5a5"&gt;chrome.experimental.omnibox.&lt;/font&gt;onInputChanged &lt;/li&gt;    &lt;li&gt;&lt;font color="#a5a5a5"&gt;chrome.experimental.omnibox.&lt;/font&gt;onInputEntered &lt;/li&gt;    &lt;li&gt;&lt;font color="#a5a5a5"&gt;chrome.experimental.omnibox.&lt;/font&gt;onInputCancelled &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The two events you will use the most are &lt;code&gt;onInputChanged&lt;/code&gt; and &lt;code&gt;onInputEntered&lt;/code&gt;. InputChanged occurs every time you type something in the Omnibar (after typing the keyword). This is also the event where you will be inserting the suggestions you want to show up in the results list. This is done in the following manner (placed in the background.html file): &lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:011afaad-4f51-4829-8e84-be6aaddf9a0d" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;chrome.experimental.omnibox.onInputChanged.addListener(&lt;span style="color:#0000ff"&gt;function&lt;/span&gt; (text, suggest) {&lt;br&gt;     &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (text.search(&lt;span style="color:#800000"&gt;&amp;#39;coffee&amp;#39;&lt;/span&gt;) &amp;gt; -1) {&lt;br&gt;         &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; suggestions = [];&lt;br&gt; &lt;br&gt;         suggestions.push({ content: &lt;span style="color:#800000"&gt;&amp;#39;Coffee - Wikipedia&amp;#39;&lt;/span&gt;, description: &lt;span style="color:#800000"&gt;&amp;#39;Coffee - Wikipedia&amp;#39;&lt;/span&gt; });&lt;br&gt;         suggestions.push({ content: &lt;span style="color:#800000"&gt;&amp;#39;Starbucks Coffee&amp;#39;&lt;/span&gt;, description: &lt;span style="color:#800000"&gt;&amp;#39;Starbucks Coffee&amp;#39;&lt;/span&gt; });&lt;br&gt; &lt;br&gt;         suggest(suggestions);&lt;br&gt;     }&lt;br&gt; });&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;The suggest function we are calling at the end wants an array of suggestions. Each suggestion object has tree properties; content, description, and descriptionStyles (optional). The content property is the value the address bar will get when we choose this suggestion, and also the value we receive in the onInputEntered event. The description is the text we see in the results list. Lastly the descriptionStyles; it lets us style the description in different ways, e.g. green, grayed and bold. More on how this works later.&lt;/p&gt;  &lt;p&gt;When running this code and typing our keyword in the Omnibox (e.g. “&lt;em&gt;sp&lt;/em&gt;”), pressing space, and typing “coffee” you will get the following results:&lt;/p&gt;  &lt;p&gt;&lt;img class="wlDisabledImage" title="omnibox-3" border="0" alt="omnibox-3" src="http://assets.codingbug.com/uploads/WindowsLiveWriter/f1ca58cf933f_10CA3/omnibox-3_0c535b29-9279-4564-b398-75decd1efa9b.png" width="608" height="122"&gt;&lt;/p&gt;  &lt;p&gt;Pretty awesome, right! Now this example is quite useless but we could do something much smarter such as submitting this command to a web server, which then starts the coffeemaker and a notification popup is shown when it’s ready.&lt;/p&gt;  &lt;p&gt;Whenever you press &lt;kbd&gt;enter&lt;/kbd&gt; the value will be sent to the event listeners of the &lt;code&gt;onInputEntered&lt;/code&gt; event. This event receives the entered text through it’s first parameter “text”. See example:&lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c589de71-4ce1-4ec6-9449-b73b4525a774" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;chrome.experimental.omnibox.onInputEntered.addListener(&lt;span style="color:#0000ff"&gt;function&lt;/span&gt; (text) {&lt;br&gt;     alert(&lt;span style="color:#800000"&gt;&amp;#39;You entered: &amp;#39;&lt;/span&gt; + text);&lt;br&gt; });&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;If you liked the idea about the coffeemaker, then here is where you will send the command to the web server. Or whatever you like it to do!&lt;/p&gt;  &lt;h3&gt;Beautify it&lt;/h3&gt;  &lt;p&gt;The suggestions objects we created earlier only used the content and description properties, and leaving out the descriptionStyles property. This property is quite cool (and nicely implemented). It determines how the description will look in the results list. We can choose between four different styles:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;styleDim – slightly grayed out, used for helper text&lt;/li&gt;    &lt;li&gt;styleMatch – used to display matched text, in bold&lt;/li&gt;    &lt;li&gt;styleUrl – used for URLs and filenames&lt;/li&gt;    &lt;li&gt;styleNone – resets the style to normal&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&lt;font color="#333333" face="Helvetica"&gt;They are then used by inserting in an array and specifying at which offset it should take effect. This means we can stack up as many different styles we want. We only have to set the offset at which their styles begin. Lets say we have a suggestion where we will display an URL and its page title. It would look like this in code:&lt;/font&gt;&lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9055186a-f16b-4e25-bb3f-8f20932d5a72" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;&lt;span style="color:#0000ff"&gt;var&lt;/span&gt; url = &lt;span style="color:#800000"&gt;&amp;#39;http://google.com&amp;#39;&lt;/span&gt;;&lt;br&gt; &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; title = &lt;span style="color:#800000"&gt;&amp;#39;Google Search&amp;#39;&lt;/span&gt;;&lt;br&gt; &lt;br&gt; &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; suggestion = {&lt;br&gt;     content: url,&lt;br&gt;     description: url + &lt;span style="color:#800000"&gt;&amp;#39; - &amp;#39;&lt;/span&gt; + title,&lt;br&gt; &lt;br&gt;     descriptionStyles: [&lt;br&gt;         chrome.experimental.omnibox.styleUrl(0),&lt;br&gt;         chrome.experimental.omnibox.styleDim(url.length)&lt;br&gt;     ]&lt;br&gt; };&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;And this is how it looks in our Omnibar:&lt;/p&gt;  &lt;p&gt;&lt;img class="wlDisabledImage" title="omnibox-4" border="0" alt="omnibox-4" src="http://assets.codingbug.com/uploads/WindowsLiveWriter/f1ca58cf933f_10CA3/omnibox-4_7dbd8293-6894-475c-a9ac-d2b802e6c440.png" width="612" height="74"&gt;&lt;/p&gt;  &lt;h3&gt;Go create some code!&lt;/h3&gt;  &lt;p&gt;That’s all I have about the Omnibox API. It’s your turn now to create some nice extensions making use of this API, I sure will. However as noted before, you can’t upload extensions using experimental APIs to the extensions gallery. Hopefully it won’t take that long before the Chrome devs finish it.&lt;/p&gt;  &lt;p&gt;If anything’s unclear, feel free to leave a comment :-)&lt;/p&gt;  &lt;h4&gt;Resources&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://code.google.com/chrome/extensions/trunk/experimental.omnibox.html" target="_blank"&gt;Omnibox API docs&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/5W06sJ6OTec" height="1" width="1"/&gt;</description>
      <category>Chrome Extensions</category>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/5W06sJ6OTec/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2010/7/26/how-to-use-the-omnibox-api-in-google-chrome/</guid>
      <pubDate>Mon, 26 Jul 2010 23:36:35 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2010/7/26/how-to-use-the-omnibox-api-in-google-chrome/</feedburner:origLink></item>
    <item>
      <title>Faking Dynamic Properties with PageTypeBuilder in EPiServer</title>
      <description>&lt;p&gt;When building websites in EPiServer you sometimes want a value of a property to be inherited from the parent page. Previously we used Dynamic Properties to have properties inherited, but when using PageTypeBuilder we are spolied with being able to code all our page type properties programactially in classes. However PageTypeBuilder doesn’t support creating Dynamic Properties, but that doesn’t stop us from creating the same functionality with ordinary properties.&lt;/p&gt;  &lt;p&gt;After reading Joel’s blog post about &lt;a href="http://joelabrahamsson.com/entry/working-with-dynamic-properties-and-page-type-builder" target="_blank"&gt;dynamic properties with PageTypeBuilder&lt;/a&gt; and trying out the snippets of code he wrote, I decided to convert it into an extension method to make it easier to implement in more properties and projects.&lt;/p&gt;  &lt;h5&gt;Extension Method&lt;/h5&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:be3e5c41-916c-4b84-b501-4f3c381ced5a" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;static&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; TProperty GetInheritedProperty&amp;lt;TPageData, TProperty&amp;gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; TPageData pageData, &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Expression&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Func&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;&amp;lt;TPageData, TProperty&amp;gt;&amp;gt; expression)&lt;/span&gt;&lt;br&gt;     &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;where&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; TPageData : &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;PageData&lt;/span&gt;&lt;br&gt;     &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;where&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; TProperty : &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;class&lt;/span&gt;&lt;br&gt; &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;br&gt;     &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (pageData == &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;br&gt;     &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (expression == &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;throw&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;ArgumentException&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;Missing expression parameter&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;, &lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515"&gt;&amp;quot;expression&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;);&lt;/span&gt;&lt;br&gt; &lt;br&gt;     &lt;span style="background:#ffffff;color:#000000"&gt;TProperty value = pageData.GetPropertyValue(expression);&lt;/span&gt;&lt;br&gt; &lt;br&gt;     &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;if&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; (value == &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &amp;amp;&amp;amp; pageData.ParentLink != &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &amp;amp;&amp;amp; pageData.PageLink != &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;PageReference&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.StartPage)&lt;/span&gt;&lt;br&gt;     &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;br&gt;         &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; page = &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;DataFactory&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.Instance.GetPage(pageData.ParentLink) &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;as&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; TPageData;&lt;/span&gt;&lt;br&gt;         &lt;span style="background:#ffffff;color:#000000"&gt;value = page != &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; ? expression.Compile()(page) : &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;null&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;;&lt;/span&gt;&lt;br&gt;     &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;br&gt; &lt;br&gt;     &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; value;&lt;/span&gt;&lt;br&gt; &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;  &lt;h5&gt;Sample Usage&lt;/h5&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e411dc90-8253-4c59-a7e0-0dd2be6bcacc" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;&lt;span style="background:#ffffff;color:#000000"&gt;[&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;PageTypeProperty&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(Type = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;typeof&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;PropertyString&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;), Tab = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;typeof&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;(&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af"&gt;Information&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;))]&lt;/span&gt;&lt;br&gt; &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; MyInheirtedProperty&lt;/span&gt;&lt;br&gt; &lt;span style="background:#ffffff;color:#000000"&gt;{&lt;/span&gt;&lt;br&gt;     &lt;span style="background:#ffffff;color:#000000"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff"&gt;this&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000"&gt;.GetInheritedProperty(page =&amp;gt; page.MyInheirtedProperty); }&lt;/span&gt;&lt;br&gt; &lt;span style="background:#ffffff;color:#000000"&gt;}&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;If you know any improvements that can be made to this method – please do leave a comment.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/jZZn5bJq5xA" height="1" width="1"/&gt;</description>
      <category>PageTypeBuilder</category>
      <category>ASP.NET</category>
      <category>EPiServer</category>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/jZZn5bJq5xA/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2010/7/21/faking-dynamic-properties-with-pagetypebuilder-in-episerver/</guid>
      <pubDate>Wed, 21 Jul 2010 11:41:00 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2010/7/21/faking-dynamic-properties-with-pagetypebuilder-in-episerver/</feedburner:origLink></item>
    <item>
      <title>To-Do Chrome Extension Part 3 – Make it Work</title>
      <description>&lt;p&gt;This is part three of the series on making a to-do extension for Google Chrome.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://thecodingbug.com/blog/2010/3/7/creating-a-to-do-extension-for-chrome-part-1/"&gt;Part 1 – Project Setup&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://thecodingbug.com/blog/2010/3/25/to-do-chrome-extension-part-2-browser-action-popup/"&gt;Part 2 – Browser Action Popup&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Part 3 – Make it Work &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In this post we are going to finish the browser action popup to a state where it is fully functional. That means being able to add, remove, edit and complete tasks. We will also apply some styling so our eyes won’t burn to death each time we look at it.&lt;/p&gt;  &lt;h3&gt;Bind event handlers&lt;/h3&gt;  &lt;p&gt;We have a lot of elements laying in our extension, that does nothing. We need to hook these up to an event handler. In JavaScript there are two ways you can add an event handler to an element. First, and most common, is by using the &lt;code&gt;addEventListener&lt;/code&gt; method (&lt;code&gt;target.addEventListener('click', handler, false)&lt;/code&gt;) or using jQuery (&lt;code&gt;$(target).click(handler)&lt;/code&gt;). These are great because they make the HTML code very clean from JavaScript and element attributes. The other way is through element attributes, e.g. &lt;code&gt;&amp;lt;a onclick=&amp;quot;handler()&amp;quot;&amp;gt;&lt;/code&gt;. In a website this easily gets messy in the markup and makes it harder to maintain. On the other hand, in extensions we write a lot more JavaScript than in a normal webpage and would rather choose to have clean and maintainable script files. This is why I will attach all event handlers through element attributes in our extension.&lt;/p&gt;  &lt;p&gt;We only need four handlers in our popup – the checkbox (&lt;code&gt;onchange&lt;/code&gt;), task textbox (&lt;code&gt;onkeyup&lt;/code&gt;), remove button (&lt;code&gt;onclick&lt;/code&gt;) and the add task textbox (&lt;code&gt;onkeyup&lt;/code&gt;), which makes our code look like this:&lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c8749430-dd6b-40ef-bc42-b3a75bc78906" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;div&lt;/span&gt; &lt;span style="color:#ff0000"&gt;id&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;results&amp;quot;&amp;gt;&lt;/span&gt;  &lt;br&gt;     &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;div&lt;/span&gt; &lt;span style="color:#ff0000"&gt;class&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;item&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;jsselect&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;$this&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;jsvalues&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;id:id&amp;quot;&amp;gt;&lt;/span&gt;&lt;br&gt;         &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;input&lt;/span&gt; &lt;span style="color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;checkbox&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;onchange&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;view.changeCompleted(this.parentNode.id, !!this.value)&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;class&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;completed&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;checked&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;checked&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;jsvalues&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;checked:completed&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;br&gt;         &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;span&lt;/span&gt; &lt;span style="color:#ff0000"&gt;class&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;title&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;onkeyup&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;view.changeTitle(this.parentNode.id, this.innerText)&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;contenteditable&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;jscontent&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;title&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;span&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;    &lt;br&gt;         &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;button&lt;/span&gt; &lt;span style="color:#ff0000"&gt;class&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;remove&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;onclick&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;view.removeTask(this.parentNode.id)&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;title&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;Remove Task&amp;quot;&amp;gt;&lt;/span&gt;Remove&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;button&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;     &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;div&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt; &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;div&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt; &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;input&lt;/span&gt; &lt;span style="color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;text&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;id&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;add&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;onkeyup&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;view.newTask(event)&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;placeholder&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;Write task and press enter...&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;You likely notice that I have included some parameters to each event handler. These help to identify which task I am changing. E.g. &lt;code&gt;this.parentNode.id&lt;/code&gt; gets the parent element’s id attribute (where we store the task’s id).&lt;/p&gt;  &lt;h3&gt;Implementing the handlers&lt;/h3&gt;  &lt;p&gt;We will be keep all our handlers in the &lt;code&gt;view&lt;/code&gt; object that we created in the previous post. The first handler is the one to add a task, called newTask. It will fire each time you type in the textbox but we only want save a new task when the user presses the enter key, which is why we need an if statement to check for that. The rest is simply adding the new task with our TaskRepository and resetting the textbox. We will also change the &lt;code&gt;init&lt;/code&gt; function a bit since last post.&lt;/p&gt;  &lt;p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:b9a7663c-f326-44ae-95f6-1963079209be" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;textbox: &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;,&lt;br&gt; &lt;br&gt; init: &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;() {&lt;br&gt;     &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.textbox = document.getElementById(&lt;span style="color:#a31515"&gt;&amp;#39;add&amp;#39;&lt;/span&gt;);&lt;br&gt;     &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.renderView();&lt;br&gt; },&lt;br&gt; &lt;br&gt; newTask: &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;(e) {&lt;br&gt;     &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (e != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; e.which == 13 &amp;amp;&amp;amp; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.textbox.value != &lt;span style="color:#a31515"&gt;&amp;quot;&amp;quot;&lt;/span&gt;) { &lt;span style="color:#008000"&gt;// enter key&lt;/span&gt;&lt;br&gt;         db.create({&lt;br&gt;             title: &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.textbox.value,&lt;br&gt;             completed: &lt;span style="color:#0000ff"&gt;false&lt;/span&gt;,&lt;br&gt;             created: &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; Date()&lt;br&gt;         });&lt;br&gt;         &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.textbox.value = &lt;span style="color:#a31515"&gt;&amp;#39;&amp;#39;&lt;/span&gt;;&lt;br&gt;         view.renderView();&lt;br&gt;     }&lt;br&gt; },&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;  &lt;p&gt;There are three handlers left to write, but they are very self explanatory and won’t need a closer description as they will merely be using methods of TaskRepository. Following is the code for &lt;code&gt;changeTitle&lt;/code&gt;, &lt;code&gt;changeCompleted&lt;/code&gt; and &lt;code&gt;removeTask&lt;/code&gt;:&lt;/p&gt;  &lt;p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c46ab81c-6559-47dd-abfe-ce6ae4741cbb" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;changeTitle: &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;(id, title) {&lt;br&gt;     db.getById(id).title = title;&lt;br&gt;     db.save();&lt;br&gt; },&lt;br&gt; &lt;br&gt; changeCompleted: &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;(id, completed) {&lt;br&gt;     db.getById(id).completed = completed;&lt;br&gt;     db.save();&lt;br&gt; },&lt;br&gt; &lt;br&gt; removeTask: &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;(id) {&lt;br&gt;     db.remove({ id: id });&lt;br&gt;     view.renderView();&lt;br&gt;     &lt;span style="color:#0000ff"&gt;return&lt;/span&gt;;&lt;br&gt; },&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;  &lt;h3&gt;Styling the popup&lt;/h3&gt;  &lt;p&gt;If you run the extension in its current state you will see that all functionality works as expected, but like I said in the previous post, it looks horrible and is hard to use. I have prepared some CSS styles for it, but as this post isn’t about CSS I won’t be getting into details about it. If you want to have a look at the CSS code, see the ZIP file at the bottom. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Before and after styling the popup:&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;img title="Before styling" border="0" alt="Before styling" src="http://assets.thecodingbug.com/uploads/WindowsLiveWriter/ToDoChromeExtensionPart3_9187/image_83d17e29-7f0a-4a8c-944c-ea9df78fbffd.png" width="240" height="181"&gt;&amp;#160; &lt;img title="image" border="0" alt="image" src="http://assets.thecodingbug.com/uploads/WindowsLiveWriter/ToDoChromeExtensionPart3_9187/image_e4cb8c8e-0555-42e1-879e-6a252e302bad.png" width="240" height="184"&gt; &lt;/p&gt;  &lt;h3&gt;Round up&lt;/h3&gt;  &lt;p&gt;In only three posts we managed to create a fully functional to-do manager for Google Chrome. This shows how easy it is to develop for Chrome with HTML 5 and JavaScript. &lt;/p&gt;  &lt;p&gt;Our extension still doesn’t fulfill all our requirements, though. We still need to implement an options page and a task counter in the icon. That’s the subject for the next post.&lt;/p&gt;  &lt;p&gt;I have “compiled” the extension to an installable .crx file in case you want to run it and see how it works. Personally I’m already using this extension for my to-do lists. &lt;/p&gt;  &lt;p&gt;Source code is, like always, available in a link below.&lt;/p&gt;  &lt;h4&gt;Downloads&lt;/h4&gt;  &lt;p&gt;&lt;a class="download bold" href="http://files.thecodingbug.com/chrome-extensions/todo/todo-part3.crx"&gt;Install extension!&lt;/a&gt;     &lt;br&gt;&lt;a class="download" href="http://files.thecodingbug.com/chrome-extensions/todo/todo-part3.zip"&gt;Download To-Do Extension Source (Part 3)&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/rjcvfnJR_Bs" height="1" width="1"/&gt;</description>
      <category>Chrome Extensions</category>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/rjcvfnJR_Bs/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2010/4/18/to-do-chrome-extension-part-3-make-it-work/</guid>
      <pubDate>Sun, 18 Apr 2010 13:05:38 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2010/4/18/to-do-chrome-extension-part-3-make-it-work/</feedburner:origLink></item>
    <item>
      <title>Client-Side Validation Using xVal and ASP.NET MVC 2</title>
      <description>&lt;p&gt;Validating input on the server-side in ASP.NET MVC 2 is quite easy when using the new Data Annotations on our Model classes. It means that we have automatic validation every time someone submits data to our Controller, the model binder of ASP.NET MVC will take care of running the validation rules we set up in the model.&lt;/p&gt;  &lt;p&gt;However the problem arises when we want client side validation on our model. We don’t want to repeat our validation rules to a client side library as that will be a pain in the ass to maintain later, when the model changes. What we do want is something that is using our preexisting rules in a way that the client side library understands.&lt;/p&gt;  &lt;p&gt;This is where xVal enters the game. It does exactly what I just described, which is converting our Data Annotation attribute-rules to rules which the excellent jQuery Validation plugin can understand. To give an example of how you can implement xVal with ASP.NET MVC, I will create a user registration form which will feature a few standard validation rules.&lt;/p&gt;  &lt;h3&gt;Validating a user registration form&lt;/h3&gt;  &lt;p&gt;Begin with &lt;a href="http://xval.codeplex.com/releases/" target="_blank"&gt;downloading xVal library&lt;/a&gt; from CodePlex and reference the file from our new and empty ASP.NET MVC 2 project in Visual Studio. Also add the &lt;code&gt;xVal.jquery.validate.js &lt;/code&gt;file to our scripts folder. We need a &lt;em&gt;user &lt;/em&gt;class to play with. Add a class named User in the Models folder and add the following code.&lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ca95fdbe-5e89-4085-97db-bd21ee53cb81" class="wlWriterSmartContent"&gt;   &lt;div class="code-block"&gt;[&lt;span style="color:#2b91af"&gt;MetadataType&lt;/span&gt;(&lt;span style="color:#0000ff"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;UserMetadata&lt;/span&gt;))]       &lt;br&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;User&lt;/span&gt; {       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Username { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Password { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Email { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Name { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }       &lt;br&gt;      &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;private&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;UserMetadata&lt;/span&gt; {       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [&lt;span style="color:#2b91af"&gt;Required&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;StringLength&lt;/span&gt;(30)]&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; Username { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }       &lt;br&gt;      &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [&lt;span style="color:#2b91af"&gt;Required&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;StringLength&lt;/span&gt;(30)]       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt; Password { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }       &lt;br&gt;      &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [&lt;span style="color:#2b91af"&gt;Required&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;DataType&lt;/span&gt;(&lt;span style="color:#2b91af"&gt;DataType&lt;/span&gt;.EmailAddress)]       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;object&lt;/span&gt; Email { &lt;span style="color:#0000ff"&gt;get&lt;/span&gt;; &lt;span style="color:#0000ff"&gt;set&lt;/span&gt;; }       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;This will require a user to enter a username, password and email address. Username and password will require a maximum of 30 characters long and the name field will be optional.&lt;/p&gt;  &lt;p&gt;We got the model, but we need somewhere to store them. For this simple demo I will be creating a dummy repository class which saves the user objects in memory, like the following snippet.&lt;/p&gt;  &lt;p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:bb96ff5e-b338-4034-9741-e42224f5b94d" class="wlWriterSmartContent"&gt;   &lt;div class="code-block"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;UserRepository&lt;/span&gt; {       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;readonly&lt;/span&gt; &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;User&lt;/span&gt;&amp;gt; _users = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;List&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af"&gt;User&lt;/span&gt;&amp;gt;();       &lt;br&gt;      &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;void&lt;/span&gt; Create(&lt;span style="color:#2b91af"&gt;User&lt;/span&gt; user) {       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#008000"&gt;// Save to database&lt;/span&gt;       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; _users.Add(user);       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;  &lt;p&gt;Now we need a controller and actions for our registration form. Two &lt;code&gt;Register&lt;/code&gt; actions will be created – one for the GET and one for the POST. The GET will simply return a View and display a registration form, with the fields of our model. When submitting the form we will get to our POST action method which will check the ModelState.IsValid property if the input data is valid, if not the method will return the View, with supplied data. Otherwise the user object is saved to our dummy database and the user is redirected to the success page.&lt;/p&gt;  &lt;p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:cf256d07-414d-4c69-9114-509c35cacf6b" class="wlWriterSmartContent"&gt;   &lt;div class="code-block"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ActionResult&lt;/span&gt; Register() {       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; View();       &lt;br&gt;}       &lt;br&gt;      &lt;br&gt;[&lt;span style="color:#2b91af"&gt;HttpPost&lt;/span&gt;]       &lt;br&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ActionResult&lt;/span&gt; Register(&lt;span style="color:#2b91af"&gt;User&lt;/span&gt; user) {       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (!ModelState.IsValid)       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; View(user);       &lt;br&gt;      &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; _userRepository.Create(user);       &lt;br&gt;      &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; RedirectToAction(&lt;span style="color:#a31515"&gt;&amp;quot;Registered&amp;quot;&lt;/span&gt;);       &lt;br&gt;}       &lt;br&gt;      &lt;br&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;ActionResult&lt;/span&gt; Registered() {       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; View();       &lt;br&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;  &lt;p&gt;If you have created the View files for these actions you should be having a fully functional registration form, with server-side validation.&lt;/p&gt;  &lt;h3&gt;Magically turn on client-side validation&lt;/h3&gt;  &lt;p&gt;The server-side validation is working, and all we ever want now is client-side validation! The steps to make that work is so easy it is laughable. We only need to include these script files in the head section.&lt;/p&gt;  &lt;p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3dcad419-8cb7-4a49-82ed-0d95f6091592" class="wlWriterSmartContent"&gt;   &lt;div class="code-block"&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;script&lt;/span&gt; &lt;span style="color:#ff0000"&gt;src&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;/scripts/jquery-1.4.2.min.js&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;script&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;script&lt;/span&gt; &lt;span style="color:#ff0000"&gt;src&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;/scripts/jquery.validate.js&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;script&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;       &lt;br&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;script&lt;/span&gt; &lt;span style="color:#ff0000"&gt;src&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;/scripts/xval.jquery.validate.js&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;script&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;  &lt;p&gt;&lt;img title="Client Side Validation with xVal" border="0" alt="Client Side Validation with xVal" align="right" src="http://assets.thecodingbug.com/uploads/WindowsLiveWriter/ClientSideValidationUsingxValand.NETMVC2_12BD3/clientsidevalidation_f9632cb5-0450-4ad8-a84e-e570be9c7390.png" width="190" height="240"&gt;Lastly we need to tell xVal to output the Data Annotation rules to our page, so that it can be read by JavaScript. This is very easily done with the following &lt;code&gt;HtmlHelper&lt;/code&gt; method, at the bottom of our View page:&lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:6bb1bf4e-79f0-43e7-8e5c-fa61d951c668" class="wlWriterSmartContent"&gt;   &lt;div class="code-block"&gt;&lt;span class="aaf"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt; Html.ClientSideValidation&amp;lt;&lt;span style="color:#2b91af"&gt;User&lt;/span&gt;&amp;gt;() &lt;span class="aaf"&gt;%&amp;gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;That’s all!? Yes, in fact that is all we have to do, to get client-side validation in ASP.NET MVC 2. Try it out, and then get back here to see what more ways you can customize xVal.&lt;/p&gt;  &lt;h3&gt;Remote validation&lt;/h3&gt;  &lt;p&gt;Sometimes only client-side validation is not enough to validate certain properties of a model. We need to validate business rules which uses a database to validate. In these cases it can be really useful to move the validation back to the server, but still keeping the snappy, instant validation that client-side validation gives us.&lt;/p&gt;  &lt;p&gt;In xVal this is possible through something that is called &lt;code&gt;RemoteRule&lt;/code&gt;. To create a Remote Rule you only need to create a new Action method in your Controller, which receives the model, validates it, and finally returns a true/false result. In our project we will check if a username is already taken, so that two users can’t have the same username. We will start with the following Action method:&lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:953ebcbf-7c01-4f11-a681-a63b38f83162" class="wlWriterSmartContent"&gt;   &lt;div class="code-block"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;RemoteValidationResult&lt;/span&gt; UsernameIsTaken(&lt;span style="color:#2b91af"&gt;User&lt;/span&gt; user) {       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; exists = _userRepository.ExistsUsername(user.Username);       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; exists       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ? &lt;span style="color:#2b91af"&gt;RemoteValidationResult&lt;/span&gt;.Failure(&lt;span style="color:#a31515"&gt;&amp;quot;Username is already taken.&amp;quot;&lt;/span&gt;)       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; : &lt;span style="color:#2b91af"&gt;RemoteValidationResult&lt;/span&gt;.Success;       &lt;br&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;I also updated the &lt;code&gt;UserRepository&lt;/code&gt; class to include an &lt;code&gt;ExistsUsername&lt;/code&gt; method which returns true if the username starts with “yadda”.&lt;/p&gt;  &lt;p&gt;To register the Remote Rule with xVal we need to open the “Register” view and find the &lt;code&gt;ClientSideValidation&lt;/code&gt; method we used earlier, and run a method on the returned object.&lt;/p&gt;  &lt;p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:04e9de7a-346d-4429-8689-3be3b358dc79" class="wlWriterSmartContent"&gt;   &lt;div class="code-block"&gt;&lt;span class="aaf"&gt;&amp;lt;%&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&lt;/span&gt; Html.ClientSideValidation&amp;lt;&lt;span style="color:#2b91af"&gt;User&lt;/span&gt;&amp;gt;()       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; .AddRule(&lt;span style="color:#a31515"&gt;&amp;quot;Username&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;RemoteRule&lt;/span&gt;(Url.Action(&lt;span style="color:#a31515"&gt;&amp;quot;UsernameIsTaken&amp;quot;&lt;/span&gt;))) &lt;span class="aaf"&gt;%&amp;gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;  &lt;p&gt;Remote Validation is now hooked up and you can try it out by typing “yadda” in the username field. It should then say the username is taken when you tab out of the field. Awesomely easy!&lt;/p&gt;  &lt;h3&gt;Custom attributes with client-side validation&lt;/h3&gt;  &lt;p&gt;In those cases where you do not need remote validation but only classic JavaScript validation will do just fine, then creating a new Data Annotation attribute is a good idea. We will use this technique when validating if a password is good-enough for us.&lt;/p&gt;  &lt;p&gt;We will start with a new class, that inherit from &lt;code&gt;ValidationAttribute&lt;/code&gt; (from Data Annotation) and implements the &lt;code&gt;ICustomRule&lt;/code&gt; interface (from xVal). From the inherited class you will override the IsValid method which does the actual validation. In this case we will use Regular Expressions to determine if the password is decent. The other method, which we got from the &lt;code&gt;ICustomRule&lt;/code&gt; interface will tell xVal which JavaScript function to run when doing the client-side validation. I have named it “GoodPassword”, and it won’t receive any parameters (&lt;em&gt;null&lt;/em&gt;). If the validation fails, it will use the error message set in the constructor.&lt;/p&gt;  &lt;p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:5e784e4f-e2de-4377-b4a7-d7b80a0126fc" class="wlWriterSmartContent"&gt;   &lt;div class="code-block"&gt;&lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;class&lt;/span&gt; &lt;span style="color:#2b91af"&gt;GoodPasswordAttribute&lt;/span&gt; : &lt;span style="color:#2b91af"&gt;ValidationAttribute&lt;/span&gt;, &lt;span style="color:#2b91af"&gt;ICustomRule&lt;/span&gt; {       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; GoodPasswordAttribute() {       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ErrorMessage = &lt;span style="color:#a31515"&gt;&amp;quot;Enter a better password.&amp;quot;&lt;/span&gt;;       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br&gt;      &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff"&gt;override&lt;/span&gt; &lt;span style="color:#0000ff"&gt;bool&lt;/span&gt; IsValid(&lt;span style="color:#0000ff"&gt;object&lt;/span&gt; value) {       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (!(value &lt;span style="color:#0000ff"&gt;is&lt;/span&gt; &lt;span style="color:#0000ff"&gt;string&lt;/span&gt;))       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;false&lt;/span&gt;;       &lt;br&gt;      &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#008000"&gt;// Requires passwords to have atleast 5 chars and one number&lt;/span&gt;       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#2b91af"&gt;Regex&lt;/span&gt;.IsMatch(value.ToString(), &lt;span style="color:#a31515"&gt;@&amp;quot;^.*(?=.{5})(?=.*\d)(?=.*\w).*$&amp;quot;&lt;/span&gt;);       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br&gt;      &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af"&gt;CustomRule&lt;/span&gt; ToCustomRule() {       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#008000"&gt;// First parameter is the JavaScript function name&lt;/span&gt;       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af"&gt;CustomRule&lt;/span&gt;(&lt;span style="color:#a31515"&gt;&amp;quot;GoodPassword&amp;quot;&lt;/span&gt;, &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;, ErrorMessage);       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; }       &lt;br&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;  &lt;p&gt;Finally the last thing is implementing the JavaScript function, which will use the same regex pattern as the server-side. The pattern could have been sent over to the JavaScript function through a parameter, but I wanted to keep them separate incase the JavaScript version needed modifications. Following is the last snippet showing the final JavaScript function.&lt;/p&gt;  &lt;p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:373ec763-92c4-4a11-9b2d-1b1c579792fb" class="wlWriterSmartContent"&gt;   &lt;div class="code-block"&gt;&lt;span style="color:#0000ff"&gt;function&lt;/span&gt; GoodPassword(value, element, params) {       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; regex = /^.*(?=.{5})(?=.*\d)(?=.*\w).*$/g;       &lt;br&gt;&amp;#160;&amp;#160;&amp;#160; &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; (value.match(regex) != &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;);       &lt;br&gt;}&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;  &lt;p&gt;Now try this in the form by typing passwords such as “&lt;span style="color: #00ff00"&gt;monster2&lt;/span&gt;” and “&lt;span style="color: #ff0000"&gt;foo&lt;/span&gt;”. We have got both client-side validation and server-side validation of our custom rule!&lt;/p&gt;  &lt;h3&gt;Summary&lt;/h3&gt;  &lt;p&gt;In this post we have covered how to implement basic client-side and server-side validation using xVal, jQuery Validation and Data Annotation in ASP.NET MVC 2. We also went further and created remote validation and custom rules for both server-side and client-side. See the demo link below for a quick look how it turned out, and download the source for a closer look.&lt;/p&gt;  &lt;p&gt;&lt;a class="download" href="http://mvc-validation-xval.thecodingbug.com/"&gt;View the demo&lt;/a&gt;     &lt;br&gt;&lt;a class="download" href="http://files.thecodingbug.com/mvc/validation/ClientSideValidationMvcXval.zip"&gt;Download the source&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/wCrH3cPPrKk" height="1" width="1"/&gt;</description>
      <category>ASP.NET MVC</category>
      <category>jQuery</category>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/wCrH3cPPrKk/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2010/3/31/client-side-validation-using-xval-and-aspnet-mvc-2/</guid>
      <pubDate>Wed, 31 Mar 2010 20:17:00 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2010/3/31/client-side-validation-using-xval-and-aspnet-mvc-2/</feedburner:origLink></item>
    <item>
      <title>To-Do Chrome Extension Part 2 – Browser Action Popup</title>
      <description>&lt;p&gt;This is part two of the series on making a to-do extension for Google Chrome.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://thecodingbug.com/blog/2010/3/7/creating-a-to-do-extension-for-chrome-part-1/"&gt;Part 1 – Project Setup&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Part 2 – Browser Action Popup &lt;/li&gt;    &lt;li&gt;&lt;a href="http://thecodingbug.com/blog/2010/4/18/to-do-chrome-extension-part-3-make-it-work/"&gt;Part 3 – Make it Work&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;In this post I will cover how to implement a good database layer for our extension, as well as how to use the jsTemplate library to display our data nicely. Fairly simple right? Let’s get to work.&lt;/p&gt;  &lt;p&gt;We will begin with writing the necessary HTML markup for displaying the tasks. To make it easier to display data from JavaScript in HTML we will be using a template system called &lt;a href="http://code.google.com/p/google-jstemplate/"&gt;jsTemplate&lt;/a&gt;, created by Google. It will allow us to separate the presentation from logic, which is always a good idea.&lt;/p&gt;  &lt;p&gt;Let’s add the jsTemplate library to our &lt;code&gt;popup.html&lt;/code&gt; file. There are three files needed to run the library, but to save some file requests I joined them to one file. You can find this file in the ZIP-archive at the bottom of this post. Extract the file in the &lt;code&gt;/js/libs/&lt;/code&gt; folder and add the following line to the head section:&lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c7c745cf-0da5-41f1-8eef-35a67b9d1c3a" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;script&lt;/span&gt; &lt;span style="color:#ff0000"&gt;src&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;js/libs/jstemplate.js&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;text/javascript&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;script&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;We need to define the properties of a task – a task will have a descriptive title, a boolean for whether the task is completed, and lastly a date of creation. Translating this to HTML markup means we need a checkbox, text element and a remove button for each task item. The date of creation will not be displayed in my version, but it is always good idea to include it incase you need it later. The template for a task item will look like the snippet below.&lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e7d1c160-4890-43d7-9d30-65187269f136" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;div&lt;/span&gt; &lt;span style="color:#ff0000"&gt;id&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;results&amp;quot;&amp;gt;&lt;/span&gt;&lt;br&gt;     &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;div&lt;/span&gt; &lt;span style="color:#ff0000"&gt;class&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;item&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;jsselect&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;$this&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;jsvalues&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;id:id&amp;quot;&amp;gt;&lt;/span&gt;&lt;br&gt;         &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;input&lt;/span&gt; &lt;span style="color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;checkbox&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;class&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;completed&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;checked&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;checked&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;jsvalues&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;checked:completed&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt; &lt;br&gt;         &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;span&lt;/span&gt; &lt;span style="color:#ff0000"&gt;class&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;title&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;contenteditable&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;true&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;jscontent&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;title&amp;quot;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;span&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;    &lt;br&gt;         &lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;button&lt;/span&gt; &lt;span style="color:#ff0000"&gt;class&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;remove&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;title&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;Remove Task&amp;quot;&amp;gt;&lt;/span&gt;Remove&lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;button&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;     &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;div&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt; &lt;span style="color:#0000ff"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515"&gt;div&lt;/span&gt;&lt;span style="color:#0000ff"&gt;&amp;gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;As you have probably already seen—there are a number of weird, non-standard attributes in the code. These are used by jsTemplate to select properties from the data we pass in. The &lt;code&gt;jsselect&lt;/code&gt; attribute means we will iterate over the variable specified in it—in this case the &lt;code&gt;$this&lt;/code&gt; variable. The &lt;code&gt;jsvalues&lt;/code&gt; attribute can change properties of the element, and &lt;code&gt;jscontent&lt;/code&gt; sets the text of the element. Now there is one more attribute that is not very commonly used in HTML, which is the &lt;code&gt;contenteditable&lt;/code&gt; attribute. It makes it possible to edit the content even though it is not an &lt;code&gt;input&lt;/code&gt; or &lt;code&gt;textarea&lt;/code&gt; element, which is perfect for this specific use-case (we can style it just like we want to).&lt;/p&gt;  &lt;p&gt;We will also need a text box for entering a new task, which will look like this:&lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:165c5646-f8d9-41b1-a7c6-639946de8d22" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;&lt;span style="color:#0000ff"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515"&gt;input&lt;/span&gt; &lt;span style="color:#ff0000"&gt;type&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;text&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;id&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;add&amp;quot;&lt;/span&gt; &lt;span style="color:#ff0000"&gt;placeholder&lt;/span&gt;&lt;span style="color:#0000ff"&gt;=&amp;quot;Write task and press enter...&amp;quot;&lt;/span&gt; &lt;span style="color:#0000ff"&gt;/&amp;gt;&lt;/span&gt;&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Just a normal input element, but with the new HTML 5 attribute called &lt;code&gt;placeholder&lt;/code&gt;. It shows the text in gray and when clicking the text box it disappears. Very cool feature, that previously required lots of scripts and styling.&lt;/p&gt;  &lt;h3&gt;Data storage in extensions&lt;/h3&gt;  &lt;p&gt;If you load the extension in Chrome it won’t really do much at all – even though we have made a template and included the necessary scripts. What we need to do is bind the data storage to the template system so that it has some data to play with. To store data in Chrome we can use two different systems, Local Storage or Web Database. The most common and easiest one is Local Storage and is also the one we will use here. It is simply an object that we can set properties on and they are automatically saved for us, even after browser restarts.&lt;/p&gt;  &lt;p class="note"&gt;Remember that localStorage can only store strings, which means you have to store your objects in a JSON-string with &lt;code&gt;JSON.stringify(object)&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;Before we get ahead of ourselves and hook up the template system (fun!), we will create a class for handling data storage. This will make it a lot easier to get, add and remove tasks from the storage.&lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:2b83932a-880c-43ba-b042-2c1ca2fd0d84" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;TaskRepository = &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;() {&lt;br&gt;     &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.init();&lt;br&gt;     &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;;&lt;br&gt; };&lt;br&gt; &lt;br&gt; TaskRepository.prototype = {&lt;br&gt;     tasks: [],&lt;br&gt;     index: 0,&lt;br&gt; &lt;br&gt;     init: &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;() {&lt;br&gt;         &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.load();&lt;br&gt;     },&lt;br&gt; &lt;br&gt;     create: &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;(task) {&lt;br&gt;         &lt;span style="color:#0000ff"&gt;if&lt;/span&gt; (task == &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;) &lt;span style="color:#0000ff"&gt;throw&lt;/span&gt; &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; TypeError(&lt;span style="color:#a31515"&gt;&amp;#39;Missing task parameter&amp;#39;&lt;/span&gt;);&lt;br&gt; &lt;br&gt;         task.id = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.index++;&lt;br&gt; &lt;br&gt;         &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.tasks.push(task);&lt;br&gt;         &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.save();&lt;br&gt;     },&lt;br&gt; &lt;br&gt;     &lt;span style="color:#008000"&gt;// &amp;#39;get&amp;#39; and &amp;#39;remove&amp;#39; functions removed for brevity,&lt;/span&gt;&lt;br&gt;     &lt;span style="color:#008000"&gt;// see ZIP-archive for full code sample.&lt;/span&gt;&lt;br&gt; &lt;br&gt;     load: &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;() {&lt;br&gt;         &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.tasks = (localStorage.tasks ? JSON.parse(localStorage.tasks) : []);&lt;br&gt;         &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.index = localStorage.index ? localStorage.index : 0;&lt;br&gt;     },&lt;br&gt; &lt;br&gt;     save: &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;() {&lt;br&gt;         localStorage.tasks = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.tasks ? JSON.stringify(&lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.tasks) : &lt;span style="color:#0000ff"&gt;null&lt;/span&gt;;&lt;br&gt;         localStorage.index = &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.index;&lt;br&gt;     }&lt;br&gt; };&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;That is quite a bit of code but quite simple at a closer look. Basically what it does is load data from &lt;code&gt;localStorage&lt;/code&gt; in &lt;code&gt;init()&lt;/code&gt; and puts it in a local variable, &lt;code&gt;tasks&lt;/code&gt;, and each method uses that variable to query data. After editing data you will have to save the data back to localStorage with the &lt;code&gt;save&lt;/code&gt; method. An index number variable is also increased every time you create a task – it is used as ID which makes it easier to get and remove a specific task.&lt;/p&gt;  &lt;h3&gt;Hook up the template system and display some data&lt;/h3&gt;  &lt;p&gt;We are now ready to display some data in our browser action popup. To do that we create a &lt;code&gt;View&lt;/code&gt; class which will include all presentation logics like load, edit and remove. We initialize this class in the &lt;code&gt;onload&lt;/code&gt; event (and of course, in the &lt;code&gt;popup.html&lt;/code&gt; file).&lt;/p&gt;  &lt;p&gt;  &lt;p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:3b6c1710-2354-4e7a-a5ae-a7c3236a4fac" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;View = &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;() { &lt;span style="color:#0000ff"&gt;return&lt;/span&gt; &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;; }&lt;br&gt; View.prototype = {&lt;br&gt;     init: &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;() {&lt;br&gt;         &lt;span style="color:#008000"&gt;// Manually create a task&lt;/span&gt;&lt;br&gt;         db.create({&lt;br&gt;             title: &lt;span style="color:#a31515"&gt;&amp;#39;My first task is to make a task&amp;#39;&lt;/span&gt;,&lt;br&gt;             completed: &lt;span style="color:#0000ff"&gt;false&lt;/span&gt;,&lt;br&gt;             created: &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; Date()&lt;br&gt;         });&lt;br&gt;         &lt;br&gt;         &lt;span style="color:#0000ff"&gt;this&lt;/span&gt;.renderView();&lt;br&gt;     },&lt;br&gt; &lt;br&gt;     renderView: &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;() {&lt;br&gt;         &lt;span style="color:#008000"&gt;// Tells jsTemplate to load our tasks and display them with our template&lt;/span&gt;&lt;br&gt;         jstProcess(&lt;span style="color:#0000ff"&gt;new&lt;/span&gt; JsEvalContext(db.tasks), document.getElementById(&lt;span style="color:#a31515"&gt;&amp;#39;results&amp;#39;&lt;/span&gt;));&lt;br&gt;     }&lt;br&gt; };&lt;br&gt; &lt;br&gt; &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; db = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; TaskRepository();&lt;br&gt; &lt;span style="color:#0000ff"&gt;var&lt;/span&gt; view = &lt;span style="color:#0000ff"&gt;new&lt;/span&gt; View();&lt;br&gt; &lt;br&gt; window.onload = &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;() { view.init(); };&lt;/div&gt; &lt;/div&gt;  &lt;h3&gt;Round up&lt;/h3&gt;  &lt;p&gt;&lt;img title="task" border="0" alt="task" align="right" src="http://assets.thecodingbug.com/uploads/WindowsLiveWriter/ToDoChromeExtensionPart2ImplementBrowser_C142/task_1291b121-c4c1-479d-8d3a-614180b461e6.png" width="197" height="110"&gt; If you reload the extension in Chrome you should see one task appearing in the list, and you should also notice that the layout is worse than the web was ‘99 (see image). There is no way to add a task either, nor remove or edit yet. In the &lt;a href="http://thecodingbug.com/blog/2010/4/18/to-do-chrome-extension-part-3-make-it-work/" target="_blank"&gt;next post&lt;/a&gt; we will fix all these points.&lt;/p&gt;  &lt;h4&gt;Download the Source&lt;/h4&gt;  &lt;p&gt;&lt;a class="download" title="Zip archive of all the files created in this post" href="http://files.thecodingbug.com/chrome-extensions/todo/todo-part2.zip"&gt;Download To-Do Extension Source (Part 2)&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/5OdKsa-lcJk" height="1" width="1"/&gt;</description>
      <category>Chrome Extensions</category>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/5OdKsa-lcJk/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2010/3/25/to-do-chrome-extension-part-2-browser-action-popup/</guid>
      <pubDate>Thu, 25 Mar 2010 20:35:41 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2010/3/25/to-do-chrome-extension-part-2-browser-action-popup/</feedburner:origLink></item>
    <item>
      <title>Experimental APIs in Chrome Extensions - #1</title>
      <description>&lt;p&gt;This post covers the new Chrome Extension API methods which are in development. Some of which are already in the dev release of Google Chrome (5.0.356.2). Most of these methods will most likely change before they are released in the stable channel, but it will give you an idea of what you can expect from the extension API in the future.&lt;/p&gt;  &lt;h3&gt;Enabling experimental APIs&lt;/h3&gt;  &lt;p&gt;To use the experimental methods you need to first turn them on in both Chrome and on per extension basis. Begin with adding &lt;code&gt;--enable-experimental-extension-apis&lt;/code&gt; to the command arguments of Chrome. Next find the extension you want to try the experimental APIs on and add &lt;code&gt;experimental&lt;/code&gt; to the permission section of the manifest file.&lt;/p&gt;  &lt;h3&gt;Clipboard (&lt;a href="http://code.google.com/chrome/extensions/trunk/experimental.clipboard.html"&gt;chrome.experimental.clipboard&lt;/a&gt;)&lt;/h3&gt;  &lt;p&gt;Copying text is already possible in Chrome by selecting text in a textarea and executing the &lt;code&gt;execCommand(&amp;quot;Copy&amp;quot;)&lt;/code&gt; method. Though, this is quite a hacky way so it is great to know that this will now be offered through an API method. Methods for cutting and pasting data is also available. &lt;/p&gt;  &lt;p&gt;Following is an example of usage:&lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:16b011d8-a44a-42cc-9fa6-6d6583557de9" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;&lt;span style="color:#008000"&gt;// Select&lt;/span&gt;&lt;br&gt; document.getElementById(&lt;span style="color:#a31515"&gt;&amp;#39;textarea1&amp;#39;&lt;/span&gt;).select();&lt;br&gt; &lt;br&gt; &lt;span style="color:#008000"&gt;// Copy/Cut [executeCopy(tabid, callback)]&lt;/span&gt;&lt;br&gt; chrome.experimental.clipboard.executeCopy(1, &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;() {&lt;br&gt;     console.log(&lt;span style="color:#a31515"&gt;&amp;#39;copied!&amp;#39;&lt;/span&gt;);&lt;br&gt; &lt;br&gt;     &lt;span style="color:#008000"&gt;// Focus an element&lt;/span&gt;&lt;br&gt;     document.getElementById(&lt;span style="color:#a31515"&gt;&amp;#39;textarea2&amp;#39;&lt;/span&gt;).focus();&lt;br&gt; &lt;br&gt;     &lt;span style="color:#008000"&gt;// Paste [executePaste(tabid, callback)]&lt;/span&gt;&lt;br&gt;     chrome.experimental.clipboard.executePaste(1, &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;() {&lt;br&gt;         console.log(&lt;span style="color:#a31515"&gt;&amp;#39;pasted!&amp;#39;&lt;/span&gt;);&lt;br&gt;     });&lt;br&gt; });&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;What I am missing is a method where I can pass a string as an argument, which will be copied directly, without needing to select the text beforehand. &lt;/p&gt;  &lt;h3&gt;Infobar (&lt;a href="http://code.google.com/chrome/extensions/trunk/experimental.infobars.html"&gt;chrome.experimental.infobars&lt;/a&gt;)&lt;/h3&gt;  &lt;p&gt;&lt;img title="chrome-experimental-infobar2" border="0" alt="chrome-experimental-infobar2" src="http://assets.thecodingbug.com/uploads/WindowsLiveWriter/ExperimentalChromeExtensionMethods1_A385/chrome-experimental-infobar2_ec7f747a-245f-47bb-9ea2-44dcd68c7fd6.png" width="623" height="117"&gt;You are most likely familiar with infobars from when you login to a web page and Chrome asks if it should remember your login. Infobars can be used when you want to alert users of a completed action, or when you want to give user a choice to take an action (e.g. backup the extensions data).&lt;/p&gt;  &lt;p&gt;Following is an example usage:   &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d95a604d-b513-4f07-af9b-ba70faef3331" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;&lt;span style="color:#008000"&gt;// Show an infobar [show(details, callback)]&lt;/span&gt;&lt;br&gt; chrome.experimental.infobars.show({ path: &lt;span style="color:#a31515"&gt;&amp;#39;infobar.html&amp;#39;&lt;/span&gt; }, &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;(window) {&lt;br&gt;     console.log(&lt;span style="color:#a31515"&gt;&amp;#39;Infobar showed, in window &amp;#39;&lt;/span&gt;, window);&lt;br&gt; });&lt;/div&gt; &lt;/div&gt; &lt;/p&gt;  &lt;p&gt;It would be great if we got some default CSS styles for buttons and links for a consistent look, as currently we have to style them ourselves. I am pretty sure this is in the pipeline, though.&lt;/p&gt;  &lt;h3&gt;Idle (&lt;a href="http://chrome.thecodingbug.com/dev#search-idle"&gt;chrome.experimental.idle&lt;/a&gt;)&lt;/h3&gt;  &lt;p&gt;This API is quite interesting. It allows us to query which state (idle, active) Chrome currently is in. This can be useful when you want to run a certain process when Chrome gets in idle state, e.g. pause the music of a music player after being idle for 30 minutes.&lt;/p&gt;  &lt;p&gt;Following is an example usage:&lt;/p&gt;  &lt;div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:91c92f0a-4267-4d34-aa70-1ed9e1574aca" class="wlWriterEditableSmartContent"&gt; &lt;div class="code-block"&gt;&lt;span style="color:#008000"&gt;// Find out which state Chrome is in. [queryState(threshold, callback)]&lt;/span&gt;&lt;br&gt; chrome.experimental.idle.queryState(15, &lt;span style="color:#0000ff"&gt;function&lt;/span&gt;(state) {&lt;br&gt;     console.log(&lt;span style="color:#a31515"&gt;&amp;#39;Chrome is in &amp;#39;&lt;/span&gt;, state, &lt;span style="color:#a31515"&gt;&amp;#39; state.&amp;#39;&lt;/span&gt;);&lt;br&gt; });&lt;br&gt; &lt;br&gt; &lt;span style="color:#008000"&gt;// Event which fires when state changes&lt;/span&gt;&lt;br&gt; chrome.experimental.idle.onStateChanged.addListener(&lt;span style="color:#0000ff"&gt;function&lt;/span&gt;(state) {&lt;br&gt;     console.log(&lt;span style="color:#a31515"&gt;&amp;#39;Changed to &amp;#39;&lt;/span&gt;, state, &lt;span style="color:#a31515"&gt;&amp;#39; state.&amp;#39;&lt;/span&gt;);&lt;br&gt; });&lt;/div&gt; &lt;/div&gt;  &lt;p&gt;Currently the documentation for this API is not ready (or the API itself for that matter) which means I don’t know which unit the threshold is in, but we can assume it is in seconds.&lt;/p&gt;  &lt;h3&gt;Stay up to date&lt;/h3&gt;  &lt;p&gt;As these experimental APIs changes a lot before they are released it is a good idea to check back at the &lt;a href="http://code.google.com/chrome/extensions/trunk/experimental.html"&gt;documentation at Google Code&lt;/a&gt; regularly. You can also have a look at the latest trunk, more specifically the &lt;a href="http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/api/extension_api.json?view=markup"&gt;extension_api.json&lt;/a&gt; file, for the absolute latest APIs.&lt;/p&gt;  &lt;p&gt;These were only some of the experimental APIs the extension API offers, for more a full documentation see the links above. I will also continue writing these type of posts for the experimental APIs in Chrome.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheCodingBug/~4/q8YRf007XTY" height="1" width="1"/&gt;</description>
      <category>Chrome Extensions</category>
      <link>http://feedproxy.google.com/~r/TheCodingBug/~3/q8YRf007XTY/</link>
      <guid isPermaLink="false">http://thecodingbug.com/blog/2010/3/20/experimental-chrome-extension-apis-1/</guid>
      <pubDate>Sat, 20 Mar 2010 13:35:48 GMT</pubDate>
    <feedburner:origLink>http://thecodingbug.com/blog/2010/3/20/experimental-chrome-extension-apis-1/</feedburner:origLink></item>
  </channel>
</rss>
