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

<channel>
	<title>Codelab Blog</title>
	<atom:link href="http://blog.codelab.co.nz/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codelab.co.nz</link>
	<description>Technical Articles and News from Codelab Ltd</description>
	<lastBuildDate>Thu, 17 May 2012 07:24:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Referenced Projects in a solution disappear on compile time Visual Studio 2010</title>
		<link>http://blog.codelab.co.nz/2012/05/17/referenced-projects-in-a-solution-disappear-on-compile-time-visual-studio-2010/</link>
		<comments>http://blog.codelab.co.nz/2012/05/17/referenced-projects-in-a-solution-disappear-on-compile-time-visual-studio-2010/#comments</comments>
		<pubDate>Thu, 17 May 2012 07:24:01 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=385</guid>
		<description><![CDATA[Take the following example of a solution: MyProject MyProject.Core MyProject.Infrasturcture I decide to add a new console application called MyProject.Console. I reference the MyProject.Core into this console application. Everything is working fine until I try to build and run the &#8230; <a href="http://blog.codelab.co.nz/2012/05/17/referenced-projects-in-a-solution-disappear-on-compile-time-visual-studio-2010/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Take the following example of a solution:</p>
<ul>
<li>MyProject</li>
<li>MyProject.Core</li>
<li>MyProject.Infrasturcture</li>
</ul>
<p>I decide to add a new console application called MyProject.Console.  I reference the MyProject.Core into this console application.  Everything is working fine until I try to build and run the console application. I get a error saying <b>&#8220;Could not find the referenced Assembly.&#8221;</b>.</p>
<p>
I figured out that when I created the new console application in Visual Studio 2010 it defaulted to .NET 4 Client Profile as the framework and not .NET 4.   This is because all my other projects were using the .NET 4 framework.
</p>
<p><i>References</i></p>
<p><a href="http://stackoverflow.com/questions/4286599/referenced-project-gets-lost-at-compile-time" title="refenced project gets lost at compile time">http://stackoverflow.com/questions/4286599/referenced-project-gets-lost-at-compile-time</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2012/05/17/referenced-projects-in-a-solution-disappear-on-compile-time-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The property could not be set to a &#8216;Int16&#8242; value. You must set this property to a non-null value of type &#8216;Int32&#8242;.</title>
		<link>http://blog.codelab.co.nz/2012/05/15/the-property-could-not-be-set-to-a-int16-value-you-must-set-this-property-to-a-non-null-value-of-type-int32/</link>
		<comments>http://blog.codelab.co.nz/2012/05/15/the-property-could-not-be-set-to-a-int16-value-you-must-set-this-property-to-a-non-null-value-of-type-int32/#comments</comments>
		<pubDate>Tue, 15 May 2012 10:04:06 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Entity Framework]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=380</guid>
		<description><![CDATA[I came across the following error when trying to map a stored procedure to a complex type in EF 4+. The property could not be set to a &#8216;Int16&#8242; value. You must set this property to a non-null value of &#8230; <a href="http://blog.codelab.co.nz/2012/05/15/the-property-could-not-be-set-to-a-int16-value-you-must-set-this-property-to-a-non-null-value-of-type-int32/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I came across the following error when trying to map a stored procedure to a complex type in EF 4+. </p>
<blockquote><p>The property could not be set to a &#8216;Int16&#8242; value. You must set this property to a non-null value of type &#8216;Int32&#8242;.</p></blockquote>
<p>The problem was the Entity Framework was thinking the return data type was Int16 but in fact the complex type value  was specified as Int32.</p>
<p>The solution was to make sure that your results from the stored procedure are explicitly set and cast to the right data types.  You can do this by using the convert function in T-SQL.  Example below.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;select convert(int,myValue) from foo</div></td></tr></tbody></table></div>
<p>Once you do implement this function into your stored procedures, you can update your mappings in EF and the problem will be fixed (well for me anyway).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2012/05/15/the-property-could-not-be-set-to-a-int16-value-you-must-set-this-property-to-a-non-null-value-of-type-int32/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Giving Enum&#8217;s descriptions</title>
		<link>http://blog.codelab.co.nz/2012/05/14/giving-enums-descriptions/</link>
		<comments>http://blog.codelab.co.nz/2012/05/14/giving-enums-descriptions/#comments</comments>
		<pubDate>Mon, 14 May 2012 08:13:37 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=376</guid>
		<description><![CDATA[Enums are very good for giving descriptions to values especially numeric values. By default though a enum value name cannot have spaces. Look at the following which shows an example of no spaces between the first enum value name. 1234enum &#8230; <a href="http://blog.codelab.co.nz/2012/05/14/giving-enums-descriptions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Enums are very good for giving descriptions to values especially numeric values.  By default though a enum value name cannot have spaces.  Look at the following which shows an example of no spaces between the first enum value name.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">enum myEnum<br />
{<br />
&nbsp; &nbsp;Icannothaveaspace = 1<br />
}</div></td></tr></tbody></table></div>
<p>
A good way to solve this problem is to use the Description attribute from the System.ComponentModel namespace.  We can use this attribute to give each enum value a descriptive meaning.
</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">using System.ComponentModel;<br />
<br />
&nbsp;public enum MyEnum<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; [Description(&quot;Authorised Contact&quot;)]<br />
&nbsp; &nbsp; &nbsp; &nbsp; AuthorisedContact = 1,<br />
&nbsp; &nbsp; &nbsp; &nbsp; [Description(&quot;Assigned Contact&quot;)]<br />
&nbsp; &nbsp; &nbsp; &nbsp; CoauthorisedContact = 2<br />
&nbsp; &nbsp; }</div></td></tr></tbody></table></div>
<p>
 From here we can create a extension method that uses reflection to get the description attribute for the selected enum value.
</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">public static class Extensions<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; /// &lt;summary&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; /// Get the description of a enum value using the description attribute<br />
&nbsp; &nbsp; &nbsp; &nbsp; /// &lt;/summary&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; /// &lt;param name=&quot;value&quot;&gt;&lt;/param&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; /// &lt;returns&gt;&lt;/returns&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; public static string GetEnumDescription(this Enum value)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FieldInfo fi = value.GetType().GetField(value.ToString());<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DescriptionAttribute[] attributes =<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (DescriptionAttribute[])fi.GetCustomAttributes(<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; typeof(DescriptionAttribute),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; false);<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (attributes != null &amp;&amp; attributes.Length &gt; 0)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return attributes[0].Description;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return value.ToString();<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }</div></td></tr></tbody></table></div>
<p>
 To use this, just call GetEnumDescription to get the description of a enum value.
</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; using Extensions; //Make sure that you use this to get the extension method<br />
&nbsp; <br />
&nbsp; public myClass<br />
&nbsp; {<br />
&nbsp; &nbsp; &nbsp; public void foo()<br />
&nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var myDescription = MyEnumValue.GetEnumDescription();<br />
&nbsp; &nbsp; &nbsp; }<br />
&nbsp; }</div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2012/05/14/giving-enums-descriptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting the screen position when visiting previous page with jQuery</title>
		<link>http://blog.codelab.co.nz/2012/01/18/setting-the-screen-position-when-visiting-previous-page-with-jquery/</link>
		<comments>http://blog.codelab.co.nz/2012/01/18/setting-the-screen-position-when-visiting-previous-page-with-jquery/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 13:10:43 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=373</guid>
		<description><![CDATA[The scenario This problem came while I was working on a client’s website. Take this scenario. I have a listing page (similar to a listing page from www.trademe.co.nz or www.ascent.co.nz ). They have a lot of listings. Each listing has &#8230; <a href="http://blog.codelab.co.nz/2012/01/18/setting-the-screen-position-when-visiting-previous-page-with-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The scenario</p>
<p>This problem came while I was working on a client’s website. Take this scenario. I have a listing page (similar to a listing page from <a title="TradeMe" href="http://www.trademe.co.nz" target="_blank">www.trademe.co.nz</a> or <a title="Ascent Technologies" href="http://www.ascent.co.nz " target="_blank">www.ascent.co.nz </a>). They have a lot of listings. Each listing has a hyperlink going to a detail page which describes more about each listing.<br />
If you have quite a large page of listings, the user has to scroll down the page to find the listing they want to click on. The problem is, when they click on the link and go to the details page, what happens when the click back and they end up back at the top of the page again? This can be quite annoying. It would be “nice” to get the browser to go back to the previous position on the listing page.</p>
<p>The Approach</p>
<p>We achieve this but attach a click event handler to the specific a tags that we want to record the last clicked position from the user before we redirect to the next page. This means when the user goes back to the previous page they will be taken to the exact position on the page. When the click event happens we always override what was in the cookie so that we don’t end up with several pages and positions. We don’t want a user to go to another page they have been to before and set the scroll position, it should only happen to the previous page.</p>
<p>Here is the code</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var COOKIE_NAME = &quot;scroll&quot;;<br />
&nbsp;<br />
$(document).ready(function () {<br />
&nbsp; &nbsp; // Check to see if the user already has the cookie set to scroll<br />
&nbsp; &nbsp; var scrollPosition = getCookiePosition(COOKIE_NAME);<br />
&nbsp; &nbsp; if (scrollPosition.length &gt; 0) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; // Scroll to the position of the last link clicked<br />
&nbsp; &nbsp; &nbsp; &nbsp; window.scrollTo(0, parseInt(scrollPosition, 10));<br />
&nbsp; &nbsp; }<br />
&nbsp;<br />
&nbsp; &nbsp; // Attach an overriding click event for each link <br />
&nbsp; &nbsp; // saveScrollPosition function can be called before the user is redirected.<br />
&nbsp; &nbsp; $(&quot;a.savel&quot;).each(function () {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $(this).click(function () {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; saveScrollPosition($(this));<br />
&nbsp; &nbsp; &nbsp; &nbsp; });<br />
&nbsp; &nbsp; });<br />
});<br />
&nbsp;<br />
// Get the offset (height from top of page and the current page url) of the link element<br />
// and save it in a cookie.<br />
function saveScrollPosition(link) {<br />
&nbsp; &nbsp; var linkTop = link.offset().top;<br />
&nbsp; &nbsp; setCookie(COOKIE_NAME, &quot;pos=&quot; + linkTop + &quot;&amp;link=&quot; + escape(window.location.pathname), 1);<br />
}<br />
&nbsp;<br />
//Trim whitespaces<br />
function trim(str) {<br />
&nbsp; &nbsp;return str.replace(/^\s+|\s+$/g, '');<br />
} <br />
// Get cookie helper function<br />
function getCookiePosition(name) {<br />
&nbsp; &nbsp; if (document.cookie.length &gt; 0) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; //Get the right cookie<br />
&nbsp; &nbsp; &nbsp; &nbsp; var cookies = document.cookie.split(&quot;;&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; for (var i = 0; i &lt; cookies.length; i++) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (trim(cookies[i].split(&quot;=&quot;)[0]) == COOKIE_NAME) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Get the position of the &amp; sign<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var pos = cookies[i].indexOf(&quot;&amp;&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (pos &gt; -1) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //Get value<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var scrollValue = cookies[i].split(&quot;=&quot;)[2].substring(0, cookies[i].split(&quot;=&quot;)[2].indexOf(&quot;&amp;&quot;));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var link = unescape(trim(cookies[i].split(&quot;=&quot;)[3]));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //if the link is the same as the current page, then assume user wants to go back to the same position<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (link == window.location.pathname) return scrollValue;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return &quot;&quot;;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; return &quot;&quot;;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; return &quot;&quot;;<br />
}<br />
&nbsp;<br />
//Method to create a new cookie<br />
function createCookie(name, value, days) {<br />
&nbsp; &nbsp; if (days) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; var date = new Date();<br />
&nbsp; &nbsp; &nbsp; &nbsp; date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));<br />
&nbsp; &nbsp; &nbsp; &nbsp; var expires = &quot;; expires=&quot; + date.toGMTString();<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; else var expires = &quot;&quot;;<br />
&nbsp; &nbsp; document.cookie = name + &quot;=&quot; + value + expires + &quot;; path=/&quot;;<br />
}<br />
&nbsp;<br />
// Set cookie<br />
function setCookie(name, value, expiredays) {<br />
&nbsp; &nbsp; //Remove all other cookies<br />
&nbsp; &nbsp; var cookies = document.cookie.split(&quot;;&quot;);<br />
&nbsp; &nbsp; for (var i = 0; i &lt; cookies.length; i++) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (trim(cookies[i].split(&quot;=&quot;)[0]) == COOKIE_NAME) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createCookie(trim(cookies[i].split(&quot;=&quot;)[0]), &quot;&quot;, -1);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; //Set the new cookie<br />
&nbsp; &nbsp; createCookie(name, value, expiredays);<br />
}</div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2012/01/18/setting-the-screen-position-when-visiting-previous-page-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento Fontis Paymate Module Fix for Not Passing Data Issue</title>
		<link>http://blog.codelab.co.nz/2011/12/28/magento-fontis-paymate-module-fix-for-not-passing-data-issue/</link>
		<comments>http://blog.codelab.co.nz/2011/12/28/magento-fontis-paymate-module-fix-for-not-passing-data-issue/#comments</comments>
		<pubDate>Wed, 28 Dec 2011 03:56:29 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=370</guid>
		<description><![CDATA[I upgraded my magento from 1.4.0.1 to 1.6.1 and yes a lot of things broke especially the ability to pay using Paymate. I did some research and found a lot of people having the issue of non data being passed &#8230; <a href="http://blog.codelab.co.nz/2011/12/28/magento-fontis-paymate-module-fix-for-not-passing-data-issue/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I upgraded my magento from 1.4.0.1 to 1.6.1 and yes a lot of things broke especially the ability to pay using Paymate.<br />
I did some research and found a lot of people having the issue of non data being passed from Magento to Paymate to populate the fields like address, amount etc.   Since there has been no support at all? I decided to take matters into my own hands.</p>
<p>Here is the code from the file: /app/code/community/Fontis/Paymate/Model/Paymate.php<br />
replace this file with your original file Paymate.php.  As always I suggest that you back up everything!<br />
This worked for me.  Technically the issue was the code didn&#8217;t like getting the getQuote() from the checkout/session object.  Instead getting the getLastRealOrderId from checkout/session and loading a new model with the order id worked.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;?php<br />
/**<br />
&nbsp;* Fontis Paymate Extension<br />
&nbsp;*<br />
&nbsp;* NOTICE OF LICENSE<br />
&nbsp;*<br />
&nbsp;* This source file is subject to the Open Software License (OSL 3.0)<br />
&nbsp;* that is bundled with this package in the file LICENSE.txt.<br />
&nbsp;* It is also available through the world-wide-web at this URL:<br />
&nbsp;* http://opensource.org/licenses/osl-3.0.php<br />
&nbsp;* If you did not receive a copy of the license and are unable to<br />
&nbsp;* obtain it through the world-wide-web, please send an email<br />
&nbsp;* to license@magentocommerce.com so one can be sent to you a copy immediately.<br />
&nbsp;*<br />
&nbsp;* @category &nbsp; Fontis<br />
&nbsp;* @package &nbsp; &nbsp;Fontis_Paymate<br />
&nbsp;* @author &nbsp; &nbsp; Lloyd Hazlett<br />
&nbsp;* @author &nbsp; &nbsp; Chris Norton<br />
&nbsp;* @copyright &nbsp;Copyright (c) 2010 Fontis Pty. Ltd. (http://www.fontis.com.au)<br />
&nbsp;* @license &nbsp; &nbsp;http://opensource.org/licenses/osl-3.0.php &nbsp;Open Software License (OSL 3.0)<br />
&nbsp;*/<br />
<br />
/**<br />
&nbsp;* Paymate payment model<br />
&nbsp;*<br />
&nbsp;* @category &nbsp; Fontis<br />
&nbsp;* @package &nbsp; &nbsp;Fontis_Australia<br />
&nbsp;*/<br />
class Fontis_Paymate_Model_Paymate extends Mage_Payment_Model_Method_Abstract<br />
{<br />
&nbsp; &nbsp; const CGI_URL = 'https://www.paymate.com/PayMate/ExpressPayment';<br />
&nbsp; &nbsp; const CGI_URL_TEST = 'https://www.paymate.com/PayMate/TestExpressPayment';<br />
&nbsp; &nbsp; const REQUEST_AMOUNT_EDITABLE = 'N';<br />
<br />
&nbsp; &nbsp; protected $_code &nbsp;= 'paymate';<br />
&nbsp; &nbsp; protected $_formBlockType = 'fontis_paymate_block_form';<br />
&nbsp; &nbsp; protected $_allowCurrencyCode = array('AUD', 'EUR', 'GBP', 'NZD', 'USD');<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; protected $_isGateway &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = false;<br />
&nbsp; &nbsp; protected $_canAuthorize &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= false;<br />
&nbsp; &nbsp; protected $_canCapture &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= true;<br />
&nbsp; &nbsp; protected $_canCapturePartial &nbsp; &nbsp; &nbsp; = false;<br />
&nbsp; &nbsp; protected $_canRefund &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = false;<br />
&nbsp; &nbsp; protected $_canVoid &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = false;<br />
&nbsp; &nbsp; protected $_canUseInternal &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= false;<br />
&nbsp; &nbsp; protected $_canUseCheckout &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= true;<br />
&nbsp; &nbsp; protected $_canUseForMultishipping &nbsp;= false;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp;* Assign data to info model instance<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @param &nbsp; mixed $data<br />
&nbsp; &nbsp; &nbsp;* @return &nbsp;Fontis_Australia_Model_Payment_Paymate<br />
&nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; public function assignData($data)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $details = array();<br />
&nbsp; &nbsp; &nbsp; &nbsp; if ($this-&gt;getUsername())<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $details['username'] = $this-&gt;getUsername();<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (!empty($details)) <br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;getInfoInstance()-&gt;setAdditionalData(serialize($details));<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; return $this;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; public function getUsername()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return $this-&gt;getConfigData('username');<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; public function getUrl()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $url = $this-&gt;getConfigData('cgi_url');<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; if(!$url)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $url = self::CGI_URL_TEST;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; return $url;<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp;* Get session namespace<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @return Fontis_Australia_Model_Payment_Paymate_Session<br />
&nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; public function getSession()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return Mage::getSingleton('paymate/paymate_session');<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp;* Get checkout session namespace<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @return Mage_Checkout_Model_Session<br />
&nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; public function getCheckout()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return Mage::getSingleton('checkout/session');<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; /**<br />
&nbsp; &nbsp; &nbsp;* Get current quote<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @return Mage_Sales_Model_Quote<br />
&nbsp; &nbsp; &nbsp;*/<br />
&nbsp; &nbsp; public function getQuote()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return $this-&gt;getCheckout()-&gt;getQuote();<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; public function getCheckoutFormFields()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $orderIncrementId = $this-&gt;getCheckout()-&gt;getLastRealOrderId();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $order = Mage::getModel('sales/order')-&gt;loadByIncrementId($orderIncrementId);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; $a = $order-&gt;getShippingAddress();<br />
&nbsp; &nbsp; &nbsp; &nbsp; $b = $order-&gt;getBillingAddress();<br />
&nbsp; &nbsp; &nbsp; &nbsp; $currency_code = $order-&gt;getCurrencyCode();<br />
&nbsp; &nbsp; &nbsp; &nbsp; //$cost = $order-&gt;getSubtotal() - $order-&gt;getDiscountAmount();<br />
&nbsp; &nbsp; &nbsp; &nbsp; $cost = $order-&gt;getGrandTotal();<br />
&nbsp; &nbsp; &nbsp; &nbsp; //$shipping = $order-&gt;getShippingAmount();<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; //$_shippingTax = $order-&gt;getShippingAddress()-&gt;getTaxAmount();<br />
&nbsp; &nbsp; &nbsp; &nbsp; //$_billingTax = $order-&gt;getBillingAddress()-&gt;getTaxAmount();<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; //$tax = sprintf('%.2f', $_shippingTax + $_billingTax);<br />
&nbsp; &nbsp; &nbsp; &nbsp; //$cost = sprintf('%.2f', $cost + $tax);<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; $fields = array(<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'mid' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; $this-&gt;getUsername(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'amt' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; sprintf('%.2f', $cost + $shipping),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'amt_editable'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; self::REQUEST_AMOUNT_EDITABLE,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'currency'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; $currency_code,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'ref' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; $orderIncrementId,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'pmt_sender_email'&nbsp; &nbsp; &nbsp; =&gt; $b-&gt;getEmail(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'pmt_contact_firstname' =&gt; $b-&gt;getFirstname(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'pmt_contact_surname' &nbsp; =&gt; $b-&gt;getLastname(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'pmt_contact_phone' &nbsp; &nbsp; =&gt; $b-&gt;getTelephone(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'pmt_country' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; $b-&gt;getCountry(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'regindi_address1'&nbsp; &nbsp; &nbsp; =&gt; $b-&gt;getStreet(1),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'regindi_address2'&nbsp; &nbsp; &nbsp; =&gt; $b-&gt;getStreet(2),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'regindi_sub' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; $b-&gt;getCity(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'regindi_state' &nbsp; &nbsp; &nbsp; &nbsp; =&gt; $b-&gt;getRegion(), &nbsp; &nbsp; // Returns full state name<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'regindi_pcode' &nbsp; &nbsp; &nbsp; &nbsp; =&gt; $b-&gt;getPostcode(),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'return'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; Mage::getUrl('paymate/paymate/complete'),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'popup' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; =&gt; 'N',<br />
&nbsp; &nbsp; &nbsp; &nbsp; );<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; // Run through fields and replace any occurrences of &amp; with the word <br />
&nbsp; &nbsp; &nbsp; &nbsp; // 'and', as having an ampersand present will conflict with the HTTP<br />
&nbsp; &nbsp; &nbsp; &nbsp; // request.<br />
&nbsp; &nbsp; &nbsp; &nbsp; $filtered_fields = array();<br />
&nbsp; &nbsp; &nbsp; &nbsp; foreach ($fields as $k=&gt;$v) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $value = str_replace(&quot;&amp;&quot;,&quot;and&quot;,$v);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $filtered_fields[$k] = &nbsp;$value;<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; return $filtered_fields;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; public function createFormBlock($name)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; $block = $this-&gt;getLayout()-&gt;createBlock('paymate/paymate_form', $name)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;setMethod('paymate')<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;setPayment($this-&gt;getPayment())<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -&gt;setTemplate('fontis/paymate/form.phtml');<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; return $block;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; /*validate the currency code is avaialable to use for paypal or not*/<br />
&nbsp; &nbsp; public function validate()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; parent::validate();<br />
&nbsp; &nbsp; &nbsp; &nbsp; $currency_code = $this-&gt;getQuote()-&gt;getBaseCurrencyCode();<br />
&nbsp; &nbsp; &nbsp; &nbsp; if (!in_array($currency_code,$this-&gt;_allowCurrencyCode)) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Mage::throwException(Mage::helper('paymate')-&gt;__('Selected currency code ('.$currency_code.') is not compatabile with Paymate'));<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; return $this;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; public function onOrderValidate(Mage_Sales_Model_Order_Payment $payment)<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp;return $this;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; public function onInvoiceCreate(Mage_Sales_Model_Invoice_Payment $payment)<br />
&nbsp; &nbsp; {<br />
<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; public function canCapture()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; return true;<br />
&nbsp; &nbsp; }<br />
<br />
&nbsp; &nbsp; public function getOrderPlaceRedirectUrl()<br />
&nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return Mage::getUrl('paymate/paymate/redirect');<br />
&nbsp; &nbsp; }<br />
}</div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/12/28/magento-fontis-paymate-module-fix-for-not-passing-data-issue/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>When to use TempData in ASP.NET MVC</title>
		<link>http://blog.codelab.co.nz/2011/12/05/when-to-use-tempdata-in-asp-net-mvc/</link>
		<comments>http://blog.codelab.co.nz/2011/12/05/when-to-use-tempdata-in-asp-net-mvc/#comments</comments>
		<pubDate>Mon, 05 Dec 2011 02:27:37 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=366</guid>
		<description><![CDATA[The problem I came across this problem where I had a basic list of items and for each if these items I wanted to add a delete action on my controller. I wanted to add some error checking around the &#8230; <a href="http://blog.codelab.co.nz/2011/12/05/when-to-use-tempdata-in-asp-net-mvc/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong>The problem</strong></p>
<p>I came across this problem where I had a basic list of items and for each if these items I wanted to add a delete action on my controller. I wanted to add some error checking around the delete action so if someone attempted to modify the URL and enter a incorrect parameter into my controller, I wanted to redirect back to the previous controller and notify the user of this mistake. Take this example. I have a Product Controller and the Index Action and View lists all of the products. I have a delete action on the Product Controller which checks if the productId parameter is valid and then removes the product and redirects to the Index action using the RedirectToAction method.</p>
<p><strong>The solution</strong></p>
<p>When validating the productId, if its NOT valid simply add a new key/value to the TempData object and call the RedirectToAction method. TempData stores data for short periods of time for the current and next HTTP request. In your index view, you can check to see if your key/value pair exists and display a error message. If you refresh the page, you will notice the data from the TempData will be gone. Remember to use RedirectToAction where possible as this is more friendly with Unit Testing rather than using the HttpResponse redirect method.</p>
<p>This reference illustrates a good understanding between TempData, ViewBag and ViewData.</p>
<p><a title="Difference between ViewBag, ViewData and TempData" href="http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications" target="_blank">http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/12/05/when-to-use-tempdata-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perform ASP.NET Postback using JQuery</title>
		<link>http://blog.codelab.co.nz/2011/10/27/perform-asp-net-postback-using-jquery/</link>
		<comments>http://blog.codelab.co.nz/2011/10/27/perform-asp-net-postback-using-jquery/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 23:47:24 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[ViewState]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=363</guid>
		<description><![CDATA[Came across a situation where I needed to disable the ASP.NET button using JQuery when the user clicks on the button, this is so we stop the user from clicking the button twice while the page is doing a postback. &#8230; <a href="http://blog.codelab.co.nz/2011/10/27/perform-asp-net-postback-using-jquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Came across a situation where I needed to disable the ASP.NET button using JQuery when the user clicks on the button, this is so we stop the user from clicking the button twice while the page is doing a postback.</p>
<p>Firstly, add the following JQuery/Javascript code:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&lt;script&gt;<br />
<br />
&nbsp;function autoSubmit()<br />
&nbsp;{<br />
&nbsp;&lt;%= ClientScript.GetPostBackEventReference(btnSaveChanges, &quot;&quot;) %&gt;;<br />
&nbsp;}<br />
&nbsp; &nbsp; &nbsp;$(function () {<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(&quot;#&lt;%= btnSaveChanges.ClientID %&gt;&quot;).click(function () {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$(this).attr(&quot;disabled&quot;, &quot;true&quot;);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;autoSubmit();<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return false;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;});<br />
&nbsp; &nbsp; &nbsp;});<br />
&lt;/script&gt;</div></td></tr></tbody></table></div>
<p>You can inject the correct generated javascript code from using the function GetPostBackEventReference between the server tags.   Bind a click event to the ASP.NET server control which disables the button and call the autosubmit javascript function to perform a post back on the ASP.NET button control.   </p>
<p>References</p>
<p><a href="http://msdn.microsoft.com/en-us/library/ms153112.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/ms153112.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/10/27/perform-asp-net-postback-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Some useful Extension Methods</title>
		<link>http://blog.codelab.co.nz/2011/09/06/some-useful-extension-methods/</link>
		<comments>http://blog.codelab.co.nz/2011/09/06/some-useful-extension-methods/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 10:45:59 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=358</guid>
		<description><![CDATA[Back to basics&#8230; A couple of useful Extension methods if you are checking if a string is a valid integer or decimal. 1234567891011121314public static bool IsInteger(this string value) { if (String.IsNullOrEmpty(value)) return false; Int32 tmpNo; return Int32.TryParse(value, out tmpNo); } &#8230; <a href="http://blog.codelab.co.nz/2011/09/06/some-useful-extension-methods/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Back to basics&#8230;</p>
<p>A couple of useful Extension methods if you are checking if a string is a valid integer or decimal.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">public static bool IsInteger(this string value)<br />
{<br />
if (String.IsNullOrEmpty(value)) return false;<br />
Int32 tmpNo;<br />
return Int32.TryParse(value, out tmpNo);<br />
}<br />
<br />
<br />
public static bool IsDecimal(this string value)<br />
{<br />
if (String.IsNullOrEmpty(value)) return false;<br />
Decimal tmpNo;<br />
return Decimal.TryParse(value, out tmpNo);<br />
}</div></td></tr></tbody></table></div>
<p>To implement the Extension Methods:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var myString = &quot;10.5&quot;;<br />
<br />
if (myString.IsDecimal())<br />
<br />
{<br />
<br />
//Do something<br />
<br />
}</div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/09/06/some-useful-extension-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Areas and ASP.NET MVC Routes Tip</title>
		<link>http://blog.codelab.co.nz/2011/08/28/areas-and-asp-net-mvc-routes-tip/</link>
		<comments>http://blog.codelab.co.nz/2011/08/28/areas-and-asp-net-mvc-routes-tip/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 10:21:10 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[MVC]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Coding Practices]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=354</guid>
		<description><![CDATA[Lets say that you have several areas define in your ASP.NET MVC solution. You find that when you run your application you get the following error &#8220;Multiple types were found that match the controller named ‘Home’.&#8221;. This is because ASP.NET &#8230; <a href="http://blog.codelab.co.nz/2011/08/28/areas-and-asp-net-mvc-routes-tip/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Lets say that you have several areas define in your ASP.NET MVC solution. You find that when you run your application you get the following error <strong><em>&#8220;Multiple types were found that match the controller named ‘Home’.&#8221;</em></strong>. This is because ASP.NET MVC finds all the routing definitions (i.e in each area.cs file or the global.asax) and sees conflicts with duplicate controller names.<br />
Simple solution is to associate the namespace with the routes you are registering. Take the example below:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">// global.asax route<br />
routes.MapRoute(<br />
&quot;Default&quot;, // Route name<br />
&quot;{controller}/{action}/{id}&quot;, // URL with parameters<br />
new { controller = &quot;Home&quot;, action = &quot;Index&quot;, id = UrlParameter.Optional }, // Parameter defaults<br />
new string[] { &quot;MyApplication.Controllers&quot; } // Controller Namespace<br />
);<br />
?<br />
// Area Registration Route<br />
context.MapRoute(<br />
MyArea_default,<br />
&quot;MyArea/{controller}/{action}/{id}&quot;,<br />
new { action = &quot;Index&quot;, id = UrlParameter.Optional },<br />
new string[] { &quot;MyApplication.Areas.MyArea.Controllers&quot; }<br />
);</div></td></tr></tbody></table></div>
<p>Credit to <a href="http://steve.testasoftware.com/?p=40">Steve Testa</a>, Thanks!.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/08/28/areas-and-asp-net-mvc-routes-tip/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>OrderBy making null records come last Entity Framework and Linq</title>
		<link>http://blog.codelab.co.nz/2011/07/28/orderby-making-null-records-come-last-entity-framework-and-linq/</link>
		<comments>http://blog.codelab.co.nz/2011/07/28/orderby-making-null-records-come-last-entity-framework-and-linq/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 11:45:02 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Lambda]]></category>
		<category><![CDATA[Linq]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=352</guid>
		<description><![CDATA[Ever want to sort your result set but make sure the records with a null sorting column appear last? See the example below 12345678910var results = (from x in EntityObjectContext.MyTable &#160; &#160; &#160; &#160; &#160; &#160; &#160; select x &#160; &#8230; <a href="http://blog.codelab.co.nz/2011/07/28/orderby-making-null-records-come-last-entity-framework-and-linq/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Ever want to sort your result set but make sure the records with a null sorting column appear last?<br />
See the example below</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var results = (from x in EntityObjectContext.MyTable<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select x<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; into grp<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; select new<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mydata = grp,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myid = grp.id,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mysortingentity = grp.mysortingentity<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;).OrderBy(x =&gt; sortingcolumn == null).ThenBy(x =&gt; x.mysortingentity.Name).ThenBy(x =&gt; x.myid);</div></td></tr></tbody></table></div>
<p>Watch this space, this can easily be transformed into a Extension Method.  Check out this link <a href="http://tahirhassan.blogspot.com/2010/06/linq-to-sql-order-by-nulls-last.html">http://tahirhassan.blogspot.com/2010/06/linq-to-sql-order-by-nulls-last.html</a>, this Extension method works for LinqToSQL.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/07/28/orderby-making-null-records-come-last-entity-framework-and-linq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

