<?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 &#187; Coding Practices</title>
	<atom:link href="http://blog.codelab.co.nz/tag/coding-practices/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codelab.co.nz</link>
	<description>Technical Articles and News from Codelab Ltd</description>
	<lastBuildDate>Tue, 17 Jan 2012 13:10:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<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 MVC finds all the routing definitions (i.e in each area.cs file or the global.asax) and [...]]]></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;"><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></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>A way around page refreshes/back button problems with a simple concept</title>
		<link>http://blog.codelab.co.nz/2010/05/17/a-way-around-page-refreshesback-button-problems-with-a-simple-concept/</link>
		<comments>http://blog.codelab.co.nz/2010/05/17/a-way-around-page-refreshesback-button-problems-with-a-simple-concept/#comments</comments>
		<pubDate>Mon, 17 May 2010 09:58:24 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Coding Practices]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=231</guid>
		<description><![CDATA[The problem: You have a form in which the user fills out and clicks a &#8220;submit&#8221; button that validates their input, does some processing and output&#8217;s some results. The problem being the application needs to cater for page refreshes, back buttons and the case of the page being submitted more than once (latency/slow internet connection). [...]]]></description>
			<content:encoded><![CDATA[<p><em>The problem:</em></p>
<p>You have a form in which the user fills out and clicks a &#8220;submit&#8221; button that validates their input, does some processing and output&#8217;s some results. The problem being the application needs to cater for page refreshes, back buttons and the case of the page being submitted more than once (latency/slow internet connection).</p>
<p><em>The Solution:</em></p>
<p>Possible solutions can be (<em>this assumes not using Ajax as a solution</em>), once the user clicks the submit button the server validates the user&#8217;s input and has processed the information. Store a unique id in session and redirect to a &#8220;complete&#8221; page. If the user clicks the back button and resubmits the page, you can build logic to check if a unique id exists in session and if it does, redirect to the complete page without having to re-process the information.</p>
<p>If the user is on the complete page and refreshes the page, because its on a page which has used a GET, there is no processing done and hence no duplication of data.</p>
<p><strong><em>References:</em></strong></p>
<p><a href="http://en.wikipedia.org/wiki/Post/Redirect/Get">http://en.wikipedia.org/wiki/Post/Redirect/Get</a></p>
<p><a href="http://stackoverflow.com/questions/665399/how-do-i-stop-the-back-and-refresh-buttons-from-resubmitting-my-form">http://stackoverflow.com/questions/665399/how-do-i-stop-the-back-and-refresh-buttons-from-resubmitting-my-form</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2010/05/17/a-way-around-page-refreshesback-button-problems-with-a-simple-concept/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Best Coding Practices &#8211; TIP 4</title>
		<link>http://blog.codelab.co.nz/2009/04/04/best-coding-practices-tip-4/</link>
		<comments>http://blog.codelab.co.nz/2009/04/04/best-coding-practices-tip-4/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 08:15:42 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Coding Practices]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=109</guid>
		<description><![CDATA[Use enum&#8217;s where required.   Do not use Strings or Numbers to indicate discrete values. References: http://msdn.microsoft.com/en-us/library/sbbt4032(VS.80).aspx]]></description>
			<content:encoded><![CDATA[<p>Use enum&#8217;s where required.   Do not use Strings or Numbers to indicate discrete values.</p>
<p><em>References:</em></p>
<p><a href="http://msdn.microsoft.com/en-us/library/sbbt4032(VS.80).aspx">http://msdn.microsoft.com/en-us/library/sbbt4032(VS.80).aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2009/04/04/best-coding-practices-tip-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Best Coding Practices &#8211; TIP 3</title>
		<link>http://blog.codelab.co.nz/2009/02/20/best-coding-practices-tip-3/</link>
		<comments>http://blog.codelab.co.nz/2009/02/20/best-coding-practices-tip-3/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 08:52:02 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Coding Practices]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=78</guid>
		<description><![CDATA[The use of partial classes can help improve coding for the following reasons: As you can split code into seperate physical files, its easier to seperate UI and Business Logic that may belong in a single class Produces clean and organised code No performance hit&#8230; The compiler groups all partial classes into one entity during [...]]]></description>
			<content:encoded><![CDATA[<p>The use of partial classes can help improve coding for the following reasons:</p>
<ul>
<li>As you can split code into 	seperate physical files, its easier to seperate UI and Business 	Logic that may belong in a single class</li>
<li>Produces clean and organised code</li>
<li>No performance hit&#8230; The compiler groups all partial classes into one entity during compilation</li>
</ul>
<p style="margin-bottom: 0cm;"><em><strong>Sample Code</strong></em></p>
<p style="margin-bottom: 0cm;">MyFile1.cs</p>
<p style="margin-bottom: 0cm;">public partial class MyPartialClass</p>
<p style="margin-bottom: 0cm;">{</p>
<p style="margin-bottom: 0cm;">int foo = 0;</p>
<p style="margin-bottom: 0cm;">}</p>
<p style="margin-bottom: 0cm;">MyFile2.cs</p>
<p style="margin-bottom: 0cm;">public partial class MyPartialClass</p>
<p style="margin-bottom: 0cm;">{</p>
<p style="margin-bottom: 0cm;">public String ShowMessage()</p>
<p style="margin-bottom: 0cm;">{</p>
<p style="margin-bottom: 0cm;">return foo.ToString();</p>
<p style="margin-bottom: 0cm;">}</p>
<p style="margin-bottom: 0cm;">}</p>
<p style="margin-bottom: 0cm;"><em><strong>REMEMBER:</strong></em> Keep partial classes in the same namespace to avoid confusion!</p>
<p style="margin-bottom: 0cm;">
<p style="margin-bottom: 0cm;">
<p style="margin-bottom: 0cm;">
<p style="margin-bottom: 0cm;">
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2009/02/20/best-coding-practices-tip-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Best Coding Practices &#8211; TIP 2</title>
		<link>http://blog.codelab.co.nz/2009/02/11/coding-practices-tip-2/</link>
		<comments>http://blog.codelab.co.nz/2009/02/11/coding-practices-tip-2/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 02:43:37 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Coding Practices]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=73</guid>
		<description><![CDATA[When you throw an exception, use the throw keyword..do not throw the original exception. This way, the original call stack is preserved.]]></description>
			<content:encoded><![CDATA[<p>When you throw an exception, use the throw keyword..do not throw the original exception. This way, the original call stack is preserved.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2009/02/11/coding-practices-tip-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Best Coding Practices &#8211; TIP 1</title>
		<link>http://blog.codelab.co.nz/2009/02/11/best-coding-practices-tip-1/</link>
		<comments>http://blog.codelab.co.nz/2009/02/11/best-coding-practices-tip-1/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 02:40:37 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Coding Practices]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=72</guid>
		<description><![CDATA[Use // or /// for comments. Avoid using /* … */ This gives you the ability to generate XML documentation from VS.]]></description>
			<content:encoded><![CDATA[<p>Use // or /// for comments. Avoid using /* … */</p>
<p>This gives you the ability to generate XML documentation from VS.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2009/02/11/best-coding-practices-tip-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

