<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>techencoder &#187; C#</title>
	<atom:link href="http://techencoder.com/index.php/category/programming/dotnet/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://techencoder.com</link>
	<description>Technical ideas in a human readable format</description>
	<lastBuildDate>Tue, 31 Aug 2010 02:15:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>		<item>
		<title>Getting DataTables to work with ASP.Net MVC</title>
		<link>http://techencoder.com/index.php/2009/12/getting-datatables-to-work-with-asp-net-mvc/</link>
		<comments>http://techencoder.com/index.php/2009/12/getting-datatables-to-work-with-asp-net-mvc/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 07:13:12 +0000</pubDate>
		<dc:creator>r.claypool</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[DataTables]]></category>

		<guid isPermaLink="false">http://techencoder.com/?p=1041</guid>
		<description><![CDATA[Want to get jQuery DataTables to work in an ASP.Net MVC project ??? Here is a demo project in C# that should get you started.  If I find the time, I&#8217;ll post details on how this was put together (but I think most developers will benefit more from running and stepping through the source code [...]]]></description>
			<content:encoded><![CDATA[<p>Want to get jQuery <a href="http://www.datatables.net/">DataTables</a> to work in an ASP.Net MVC project ???</p>
<p>Here is a <a href="http://techencoder.com/wp-content/uploads/2009/12/ASP.Net-MVC-and-DataTables-Demo.zip">demo project</a> in C# that should get you started.  If I find the time, I&#8217;ll post details on how this was put together (but I think most developers will benefit more from running and stepping through the source code anyway).</p>
<p>Hope this helps someone.  Happy Programming!</p>
]]></content:encoded>
			<wfw:commentRss>http://techencoder.com/index.php/2009/12/getting-datatables-to-work-with-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Castle Windsor 2.0 in ASP.Net MVC 1.0</title>
		<link>http://techencoder.com/index.php/2009/10/castle-windsor-and-aspnet-mvc/</link>
		<comments>http://techencoder.com/index.php/2009/10/castle-windsor-and-aspnet-mvc/#comments</comments>
		<pubDate>Sat, 24 Oct 2009 05:26:33 +0000</pubDate>
		<dc:creator>r.claypool</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[Dependency Injection]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[Windsor]]></category>

		<guid isPermaLink="false">http://techencoder.com/?p=670</guid>
		<description><![CDATA[Consider yourself warned:  I&#8217;m just getting started with ASP.Net MVC, Dependency Injection (DI) and Inversion of Control (IoC), so this post is more for my benefit than yours. ASP.Net MVC 1.0 ASP.Net MVC 1.0 was released in March 2009. Read this tutorial to start learning it. Note that ASP.Net MVC is bin deployable which is [...]]]></description>
			<content:encoded><![CDATA[<p>Consider yourself warned:  I&#8217;m just getting started with ASP.Net MVC, Dependency Injection (DI) and Inversion of Control (IoC), so this post is <a title="Why blog? The best way to learn something is to teach it." href="http://stackoverflow.com/questions/745570/how-can-social-networking-sites-make-you-a-better-developer/745703#745703">more for my benefit than yours</a>.</p>
<p><img class="aligncenter size-full wp-image-698" title="warning-castle-windsor" src="http://techencoder.com/wp-content/uploads/2009/06/warning-castle-windsor.jpg" alt="warning-castle-windsor" width="600" height="158" /></p>
<h3>ASP.Net MVC 1.0</h3>
<p><a title="Download ASP.Net MVC" href="http://msdn.microsoft.com/en-us/library/dd394709.aspx">ASP.Net MVC 1.0</a> was released in March 2009. Read <a title="ASP.Net MVC Tutorial" href="http://weblogs.asp.net/scottgu/archive/2009/04/28/free-asp-net-mvc-nerddinner-tutorial-now-in-html.aspx">this tutorial</a> to start learning it. Note that ASP.Net MVC is <a title="bin deploy ASP.Net MVC" href="http://haacked.com/archive/2008/11/03/bin-deploy-aspnetmvc.aspx">bin deployable</a> which is very nice if you don&#8217;t want to install anything on the production web server.</p>
<h3>Inversion of Control and Castle Windsor</h3>
<p>Castle Windsor 2.0 was just released this Summer after <a title="Castle Windsor 2.0 RTM Released" href="http://ayende.com/Blog/archive/2009/05/05/castle-windsor-2.0-rtm-released.aspx">a very long development period</a>.  To start using it, <a href="http://www.castleproject.org/castle/download.html">go get the dlls</a> and reference them in your project.</p>
<p>If you are completely new to the IoC pattern, go <a href="http://msdn.microsoft.com/en-us/magazine/cc337885.aspx">read James Kovacs&#8217; article</a> and <a title="DimeCasts: Castle Windsor series" href="http://www.dimecasts.net/Casts/ByTag/Windsor%20Castle">watch these videos</a>.  They will get a typical .Net programmer up to speed pretty fast.  You should also go to <a href="http://martinfowler.com/articles/injection.html">the canonical source for IoC</a>, but frankly I learned more from the other links and I think you will too.</p>
<p>To learn how to configure the Windsor container in your project, <a title="Castle Windsor Documentation" href="http://www.castleproject.org/container/documentation/trunk/index.html">read the project&#8217;s documentation</a> and continue with this article for an example in ASP.Net MVC.</p>
<h3>Putting them Together</h3>
<p><img class="aligncenter size-full wp-image-696" title="castle-plus-aspnet-mvc" src="http://techencoder.com/wp-content/uploads/2009/06/castle-plus-aspnet-mvc.png" alt="castle-plus-aspnet-mvc" width="600" height="64" /></p>
<p>Getting Windsor to work in an ASP.Net MVC application is easy if you know what to do.  Most things are that way, huh?</p>
<p>For a bare bones integration, just follow these steps:</p>
<ol>
<li>Install ASP.NET MVC 1.0.  The <a title="Microsoft Web Platform Installer" href="http://www.microsoft.com/web/Downloads/platform.aspx">Web Platform Installer</a> is great for this and a ton of other projects.  Try it.  You&#8217;ll be glad you did.</li>
<li>Open VS 2008,  go to File-&gt;New-&gt;Project&#8230; and select the &#8220;<em>ASP.NET MVC Web Application</em>&#8221; project template.</li>
<li>Select &#8220;No&#8221; on the proceeding dialog.  Do not create a unit test project.</li>
<li><a title="Castle Windsor download page" href="http://www.castleproject.org/castle/download.html">Download</a> Castle Windsor 2.0</li>
<li>Copy the dlls (<em>Castle.DynamicProxy2, Castle.MicroKernel, Castle.Windsor and Castle.Core</em>) to your solution&#8217;s folder or a sub folder.</li>
<li>Add them as references to the web project. (Right-click the &#8220;References&#8221; folder, select &#8220;Add Reference&#8230;&#8221;, select the &#8220;Browse&#8221; tab and navigate to the dlls to add them.)</li>
<li>Add a new XML file to the web project.  Name it &#8220;windsor.config&#8221; and enter the following:</li>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #808080; font-style: italic;">&lt;!--Note: Since this is a web application, all components must have a lifesytle of 'transient' or 'preWebRequest' --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;components<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #808080; font-style: italic;">&lt;!--This is where we could declaratively add components to the Windsor container if we wanted to.--&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/components<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<li>Create an interface IMessageHolder and a class MessageHolder.  (We will use this code to illustrate injecting an instance of MessageHolder into the HomeController.)</li>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IMessageHolder
<span style="color: #000000;">&#123;</span>
	<span style="color: #FF0000;">string</span> GetMessage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> MessageHolder <span style="color: #008000;">:</span> IMessageHolder
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080;">#region IMessageHolder Members</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> GetMessage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> <span style="color: #666666;">&quot;Welcome to ASP.NET MVC using Castle Windsor 2.0!&quot;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #008080;">#endregion</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<li>Create a controller factory for Windsor:</li>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> WindsorControllerFactory <span style="color: #008000;">:</span> DefaultControllerFactory
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">readonly</span> IWindsorContainer _container<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> WindsorControllerFactory<span style="color: #000000;">&#40;</span>IWindsorContainer container<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		_container <span style="color: #008000;">=</span> container<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> IController GetControllerInstance<span style="color: #000000;">&#40;</span>Type controllerType<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>controllerType <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #008080; font-style: italic;">// Force an exception message from the base class.</span>
			<span style="color: #008080; font-style: italic;">// This will be more informative than what we would get otherwise,</span>
			<span style="color: #008080; font-style: italic;">// see: http://stackoverflow.com/questions/719678/custom-controller-factory-dependency-injection-structuremap-problems-with-asp/721313#721313</span>
			<span style="color: #0600FF;">return</span> <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">GetControllerInstance</span><span style="color: #000000;">&#40;</span>controllerType<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #008080; font-style: italic;">// Exception here ????</span>
		<span style="color: #008080; font-style: italic;">// Check the windsor configuration.</span>
		<span style="color: #008080; font-style: italic;">// Make sure that Windsor can match the component to load.</span>
		<span style="color: #0600FF;">return</span> _container.<span style="color: #0000FF;">Resolve</span><span style="color: #000000;">&#40;</span>controllerType<span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> IController<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> ReleaseController<span style="color: #000000;">&#40;</span>IController controller<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		_container.<span style="color: #0000FF;">Release</span><span style="color: #000000;">&#40;</span>controller<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<li>Open Global.asax.cs and replace it with the following:</li>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> MvcApplication <span style="color: #008000;">:</span> HttpApplication
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">/// &lt;remarks&gt;</span>
	<span style="color: #008080; font-style: italic;">/// This has to be static, because more than one instance</span>
	<span style="color: #008080; font-style: italic;">/// of the HttpApplication can potentially be created.</span>
	<span style="color: #008080; font-style: italic;">/// &lt;/remarks&gt;</span>
	<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> IWindsorContainer _container<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> RegisterRoutes<span style="color: #000000;">&#40;</span>RouteCollection routes<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		routes.<span style="color: #0000FF;">IgnoreRoute</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;{resource}.axd/{*pathInfo}&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		routes.<span style="color: #0000FF;">MapRoute</span><span style="color: #000000;">&#40;</span>
			<span style="color: #666666;">&quot;Default&quot;</span>, <span style="color: #008080; font-style: italic;">// Route name</span>
			<span style="color: #666666;">&quot;{controller}/{action}/{id}&quot;</span>, <span style="color: #008080; font-style: italic;">// URL with parameters</span>
			<span style="color: #008000;">new</span> <span style="color: #000000;">&#123;</span>controller <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Home&quot;</span>, action <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Index&quot;</span>, id <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #000000;">&#125;</span> <span style="color: #008080; font-style: italic;">// Parameter defaults</span>
			<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Application_Start<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		RegisterRoutes<span style="color: #000000;">&#40;</span>RouteTable.<span style="color: #0000FF;">Routes</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		InitializeWindsor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// Setup the MVC framework to use our Windsor controller factory.</span>
		ControllerBuilder.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">SetControllerFactory</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> WindsorControllerFactory<span style="color: #000000;">&#40;</span>_container<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">virtual</span> <span style="color: #0600FF;">void</span> InitializeWindsor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_container <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			_container <span style="color: #008000;">=</span> Build<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;windsor.config&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> IWindsorContainer Build<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> configPath<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		var resource <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> FileResource<span style="color: #000000;">&#40;</span>configPath<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		var interperter <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlInterpreter<span style="color: #000000;">&#40;</span>resource<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		var container <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> WindsorContainer<span style="color: #000000;">&#40;</span>interperter<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// Register controllers</span>
		container.<span style="color: #0000FF;">Register</span><span style="color: #000000;">&#40;</span>AllTypes
					   .<span style="color: #0000FF;">Of</span><span style="color: #008000;">&lt;</span>Controller<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
					   .<span style="color: #0000FF;">FromAssembly</span><span style="color: #000000;">&#40;</span>Assembly.<span style="color: #0000FF;">GetExecutingAssembly</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #008080; font-style: italic;">/* Modify the name with which the component is registered
		See: http://blog.andreloker.de/post/2009/03/28/ASPNET-MVC-with-Windsor-programmatic-controller-registration.aspx */</span>
					   .<span style="color: #0000FF;">Configure</span><span style="color: #000000;">&#40;</span>c <span style="color: #008000;">=&gt;</span> c.<span style="color: #0000FF;">LifeStyle</span>.<span style="color: #0000FF;">Transient</span>.<span style="color: #0000FF;">Named</span><span style="color: #000000;">&#40;</span>c.<span style="color: #0000FF;">Implementation</span>.<span style="color: #0000FF;">Name</span>.<span style="color: #0000FF;">ToLower</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #008080; font-style: italic;">// Register all other types.</span>
		container.<span style="color: #0000FF;">Register</span><span style="color: #000000;">&#40;</span>
			Component.<span style="color: #0600FF;">For</span><span style="color: #008000;">&lt;</span>IMessageHolder<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ImplementedBy</span><span style="color: #008000;">&lt;</span>MessageHolder<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">LifeStyle</span>.<span style="color: #0000FF;">Transient</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF;">return</span> container<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<li>Add a constructor to the HomeController and give it an IMessageHolder parameter.</li>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #000000;">&#91;</span>HandleError<span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> HomeController <span style="color: #008000;">:</span> Controller
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">readonly</span> IMessageHolder _holder<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> HomeController<span style="color: #000000;">&#40;</span>IMessageHolder holder<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            _holder <span style="color: #008000;">=</span> holder<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> ActionResult Index<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            ViewData<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Message&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> _holder.<span style="color: #0000FF;">GetMessage</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> View<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> ActionResult About<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> View<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre></div></div>

<p>
Since IMessageHolder is registered with Windsor, the container will resolve IMessageHolder to an instance of MessageHolder at run-time.  This is called <a href="http://en.wikipedia.org/wiki/Dependency_injection">dependency injection</a> because the HomeController dependency is injected through the constructor.  Of course, you could do this without an IoC container such as Windsor, but in larger (real world) applications the container will greatly simplify the process of managing dependencies, which means you have a better chance of keeping things <a href="http://en.wikipedia.org/wiki/Loose_coupling">loosely coupled</a> and falling into <a href="http://www.codinghorror.com/blog/archives/000940.html">the pit of success</a>.
</p>
<p>
Notice also that we display the message in Index() to verify that the Windsor container is giving us a valid instance of the type registered for IMessageHolder.  This is just a simple way to see the result of what occurred.
</p>
<li>Run the application and you should see the message on the home page.  Click <a href='http://techencoder.com/wp-content/uploads/2009/10/mvcwebapplication1.zip'>here</a> to download the sample project.</li>
<p><img src="http://techencoder.com/wp-content/uploads/2009/10/aspnet-and-windsor-integration.png" alt="aspnet-and-windsor-integration" title="aspnet-and-windsor-integration" width="600" height="404" class="aligncenter size-full wp-image-956" />
</ol>
<p>
<a href='http://techencoder.com/wp-content/uploads/2009/10/mvcwebapplication1.zip'>Project Source Code</a> for this post.
</p>
<p>I hope that this walk-through helps someone get started with Windsor.  It really is an incredible project to learn and if used correctly it will make your programs much better.  Have fun with it and Happy Programming!</p>
]]></content:encoded>
			<wfw:commentRss>http://techencoder.com/index.php/2009/10/castle-windsor-and-aspnet-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>LINQ-To-SQL DataContext and NullReferenceException</title>
		<link>http://techencoder.com/index.php/2009/06/linq-to-sql-datacontext-and-nullreferenceexception/</link>
		<comments>http://techencoder.com/index.php/2009/06/linq-to-sql-datacontext-and-nullreferenceexception/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 16:57:41 +0000</pubDate>
		<dc:creator>r.claypool</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://techencoder.com/?p=763</guid>
		<description><![CDATA[LINQ classes generated by the VS designer (or sqlmetal.exe) are marked partial by default. &#91;System.Data.Linq.Mapping.DatabaseAttribute&#40;Name=&#34;MyData&#34;&#41;&#93; public partial class MyDataDataContext : System.Data.Linq.DataContext &#123; // blah ... blah ... &#125; public partial class MyDataDataContext &#123; // My additional methods, constructors, etc. &#125; As I&#8217;ve shown above, this allows you to extend a class without modifying the original [...]]]></description>
			<content:encoded><![CDATA[<p>LINQ classes generated by the VS designer (or <a title="Code Generation Tool (SqlMetal.exe)" href="http://msdn.microsoft.com/en-us/library/bb386987.aspx">sqlmetal.exe</a>) are marked partial by default.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Data</span></span>.<span style="color: #0000FF;">Linq</span>.<span style="color: #0000FF;">Mapping</span>.<span style="color: #0000FF;">DatabaseAttribute</span><span style="color: #000000;">&#40;</span>Name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;MyData&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> MyDataDataContext <span style="color: #008000;">:</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Data</span></span>.<span style="color: #0000FF;">Linq</span>.<span style="color: #0000FF;">DataContext</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// blah ... blah ...</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> MyDataDataContext
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// My additional methods, constructors, etc.</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>As I&#8217;ve shown above, this allows you to extend a class without modifying the original code.  The <a title="Partial Class Definitions at MSDN" href="http://msdn.microsoft.com/en-us/library/wa80x488(VS.80).aspx">additional class definitions</a> just live somewhere else, typically in another file, and the compiler integrates them as needed.  That&#8217;s great for keeping your code out of the machine generated file, but you still need to be aware of what the machine generated code is doing before you extend it!  One thing to check is the default (sqlmetal generated) constructor when you are planning to overload it with your own. <strong>In some cases, the default constructor will initialize dependencies, so if you write an overload, make sure it calls the default constructor too:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> MyDataDataContext
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> MyDataContext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF;">this</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">// We must call the designer generated constructor because it contains initialization code.</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// blah ... blah ...</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Notice how I used the constructor initialization keyword <code>: this()</code>.<br />
From the C# Specification <a href="http://msdn.microsoft.com/en-us/library/aa645603(VS.71).aspx">Section 10.10.1</a></p>
<div style="padding-left:30px; color:Chocolate"><strong>&#8220;An instance constructor initializer of the form this(argument-listopt) causes an instance constructor from the class itself to be invoked.&#8221;</strong></div>
<div style="padding-top:10px">If your DataContext is throwing a NullReferenceException <em>&#8220;Object reference not set to an instance of an object&#8221;</em>,  make sure you are calling the default constructor.</div>
<div id="attachment_764" class="wp-caption aligncenter" style="width: 610px"><img class="size-full wp-image-764" title="null-reference-exception" src="http://techencoder.com/wp-content/uploads/2009/06/null-reference-exception.png" alt="Don't forget to call the default constructor!" width="600" height="255" /><p class="wp-caption-text">Don&#39;t forget to call the default constructor!</p></div>
<p>Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://techencoder.com/index.php/2009/06/linq-to-sql-datacontext-and-nullreferenceexception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixing FileUpload when Visibility is Changed Asynchronously</title>
		<link>http://techencoder.com/index.php/2009/02/fixing-fileupload/</link>
		<comments>http://techencoder.com/index.php/2009/02/fixing-fileupload/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 16:16:07 +0000</pubDate>
		<dc:creator>r.claypool</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Futurism]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Asynchronous]]></category>
		<category><![CDATA[enctype]]></category>
		<category><![CDATA[FileUpload]]></category>
		<category><![CDATA[UpdatePanel]]></category>

		<guid isPermaLink="false">http://techencoder.com/?p=220</guid>
		<description><![CDATA[Somehow I always seem to find edge cases where the abstractions in ASP.Net simply don&#8217;t work.  At some point in every project, they break down and I start digging into framework-generated scripts, the DOM, or HTTP request details to figure out what is going on. Last month, I built an alternative to System.Web.UI.Timer because extending [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_283" class="wp-caption aligncenter" style="width: 610px"><a href="http://www.flickr.com/photos/trainor/1229138273/" target="_blank"><img src="http://techencoder.com/wp-content/uploads/2009/02/upload-download.jpg" alt="Upload / Download, by johntrainor" title="upload-download" width="600" height="262" class="size-full wp-image-283" /></a><p class="wp-caption-text">Upload / Download, used with permission by johntrainor</p></div>
<p>Somehow I always seem to find edge cases where the abstractions in ASP.Net simply don&#8217;t work.  At some point in every project, <a title="Leaky Abstractions" href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html" target="_blank">they break down</a> and I start digging into framework-generated scripts, the DOM, or HTTP request details to figure out what is going on.</p>
<p>Last month, I built an <a title="JavaScript and Timer OnTick" href="http://techencoder.com/index.php/2009/01/javascript-and-timer-ontick/" target="_blank">alternative to System.Web.UI.Timer</a> because extending it with client side events would have been much more complicated than a plain JavaScript implementation.  This month, I spent almost an entire day finding out why a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.aspx" title="FileUpload Documentation on MSDN" target="_blank">FileUpload</a> would sometimes fail to send data back to the server.  The problem arises whenever visibility is changed during an async postback:</p>
<p><strong>The Problem:</strong></p>
<p>Suppose you have a FileUpload inside an UpdatePanel.  It is initially set invisible because the user is supposed to do something before seeing it.  In this example, a button click asynchronously posts back to the server and the server makes the FileUpload visible.  The page would look something like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ Page Language<span style="color: #008000;">=</span><span style="color: #666666;">&quot;C#&quot;</span> <span style="color: #008000;">%&gt;</span>
<span style="color: #008000;">&lt;</span>script runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Initially set the FileUpload invivible.</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>Page.<span style="color: #0000FF;">IsPostBack</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">fileUploadPanel</span>.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> showButton_Click<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// User has requested the FileUpload.  Make it visible.</span>
        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">fileUploadPanel</span>.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> submitButton_Click<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Did the FileUpload send data back to the server?  </span>
        <span style="color: #008080; font-style: italic;">// Print out true or false.</span>
        statusLabel.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> 
            <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;File was found = {0}&quot;</span>, fileUpload.<span style="color: #0000FF;">HasFile</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #008000;">&lt;/</span>script<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>html xmlns<span style="color: #008000;">=</span><span style="color: #666666;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>head id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Head1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>title<span style="color: #008000;">&gt;&lt;/</span>title<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>head<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>body<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>form id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;form1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>ScriptManager ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;sm&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> <span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>UpdatePanel ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;updatePanel&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> UpdateMode<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Conditional&quot;</span><span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>ContentTemplate<span style="color: #008000;">&gt;</span>
            <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Button ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;showButton&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> Text<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Show FileUpload&quot;</span> 
            OnClick<span style="color: #008000;">=</span><span style="color: #666666;">&quot;showButton_Click&quot;</span> <span style="color: #008000;">/&gt;</span>
            <span style="color: #008000;">&lt;</span>br <span style="color: #008000;">/&gt;</span>
            <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Panel ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;fileUploadPanel&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
                <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>FileUpload ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;fileUpload&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> <span style="color: #008000;">/&gt;</span>
                <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Button ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;submitButton&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> Text<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Submit&quot;</span> 
                OnClick<span style="color: #008000;">=</span><span style="color: #666666;">&quot;submitButton_Click&quot;</span> <span style="color: #008000;">/&gt;</span>
            <span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>Panel<span style="color: #008000;">&gt;</span>
            <span style="color: #008000;">&lt;</span>br <span style="color: #008000;">/&gt;</span>
            <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Label ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;statusLabel&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> <span style="color: #008000;">/&gt;</span>
        <span style="color: #008000;">&lt;/</span>ContentTemplate<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>Triggers<span style="color: #008000;">&gt;</span>
            <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>AsyncPostBackTrigger ControlID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;showButton&quot;</span> <span style="color: #008000;">/&gt;</span>
            <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>PostBackTrigger ControlID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;submitButton&quot;</span> <span style="color: #008000;">/&gt;</span>
        <span style="color: #008000;">&lt;/</span>Triggers<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>UpdatePanel<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>form<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>body<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>html<span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p>The problem with this implementation is that <strong>the FileUpload fails to send a file on the first submission after it is made visible.</strong> Subsequent submissions work fine, but we need a solution that always works.</p>
<p><strong>The First Solution (not great):</strong></p>
<p>Several programmers <a title="FileUpload Failure Question1" href="http://forums.asp.net/t/1336476.aspx" target="_blank">have</a> <a title="FileUpload Failure Question2" href="http://forums.asp.net/t/1060363.aspx" target="_blank">noticed</a> that setting the visibility false <em>on the server</em> can cause this problem, so an easy fix is to toggle visibility client side:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">fileUploadPanel</span>.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// fails</span>
<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">fileUploadPanel</span>.<span style="color: #0000FF;">Style</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;display&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;none&quot;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// works</span></pre></td></tr></table></div>

<p>Using <code>.Style["display"]</code> in lieu of <code>.Visible</code> is fine, but now the server sends the FileUpload to the browser with <em>every request</em>.  In some cases, that is not what you want.  You might want to reduce unnecessary data transfer or you might have client scripts that assume the control does not exist when it is not visible, etc.  This solution is also problematic in that you can apply the fix without knowing <em>why</em> it works.</p>
<p><strong>The Second Solution (much better):</strong></p>
<p>Going back to run our original markup, an examination of the DOM using <a href="http://getfirebug.com/" target="_blank" title="Get FireBug for FireFox">Firebug</a> or <a href="http://en.wikipedia.org/wiki/IE_Developer_Toolbar" target="_blank" title="Internet Explorer Developer Toolbar">IE Developer Toolbar</a> reveals that there is a difference in the form tag whenever the post fails or succeeds.  It was not obvious at first glance, but using <a href="http://en.wikipedia.org/wiki/WinMerge" title="WinMerge: An open source file comparison tool" target="_blank">WinMerge</a> helped to point it out.</p>
<p>DOM markup before a failed POST  (first attempt):<br />
<img src="http://techencoder.com/wp-content/uploads/2009/02/before-failure1.png" alt="Markup before a failed file upload" title="Markup before a failed file upload" width="594" height="56" class="aligncenter size-full wp-image-238" /></p>
<p>DOM markup before a successful POST (subsequent attempts):<br />
<img src="http://techencoder.com/wp-content/uploads/2009/02/before-success.png" alt="Markup before a successful file upload" title="Markup before a successful file upload" width="594" height="75" class="aligncenter size-full wp-image-239" /></p>
<p>Apparently, the ASP.Net runtime adds <a title="Enctype Attribute Information" href="http://www.htmlcodetutorial.com/forms/_FORM_ENCTYPE.html" target="_blank"><code>enctype="multipart/form-data"</code></a> to the form tag whenever it recognizes a FileUpload (or <a title="Input Type File Information" href="http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_FILE.html" target="_blank">other file input</a>) is being sent to the browser.  Setting the visibility false during initial page load prevents this, and the runtime no longer adds the attribute.  </p>
<p>Using <code>Style["display"] = "none"</code> &#8212; our first solution &#8212; fixes the problem in a roundabout way:  It causes the FileUpload to be sent to the browser on initial page load which in turn causes the runtime to add an enctype.  The presence of <a href="http://www.htmlcodetutorial.com/forms/_FORM_ENCTYPE.html" target="_blank" title="building a simple html file upload">enctype is really what we need</a>, but since showButton is an AsyncPostBackTrigger, the form tag (being outside the UpdatePanel) is not updated when showButton is clicked.  You have to manually add <a href="http://www.htmlcodetutorial.com/forms/_FORM_ENCTYPE.html" target="_blank" title="html enctype information">enctype</a> at some point before the FileUpload is made visible on the page.</p>
<p>There are several ways to ensure that this attribute is added to the form.  Anyone reading this far into the post will probably know how to do that, but here is a working example just for closure.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ Page Language<span style="color: #008000;">=</span><span style="color: #666666;">&quot;C#&quot;</span> <span style="color: #008000;">%&gt;</span>
<span style="color: #008000;">&lt;</span>script runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Initially set the FileUpload invivible.</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>Page.<span style="color: #0000FF;">IsPostBack</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">fileUploadPanel</span>.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> showButton_Click<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// User has requested the FileUpload.  Make it visible.</span>
        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">fileUploadPanel</span>.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> submitButton_Click<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Did the FileUpload send data back to the server?  </span>
        <span style="color: #008080; font-style: italic;">// Print out true or false.</span>
        statusLabel.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> 
            <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;File was found = {0}&quot;</span>, fileUpload.<span style="color: #0000FF;">HasFile</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #008000;">&lt;/</span>script<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>html xmlns<span style="color: #008000;">=</span><span style="color: #666666;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>head id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Head1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>title<span style="color: #008000;">&gt;&lt;/</span>title<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>head<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>body<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>form id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;form1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ENCTYPE<span style="color: #008000;">=</span><span style="color: #666666;">&quot;MULTIPART/FORM-DATA&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>ScriptManager ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;sm&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> <span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>UpdatePanel ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;updatePanel&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> UpdateMode<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Conditional&quot;</span><span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>ContentTemplate<span style="color: #008000;">&gt;</span>
            <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Button ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;showButton&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> Text<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Show FileUpload&quot;</span> 
            OnClick<span style="color: #008000;">=</span><span style="color: #666666;">&quot;showButton_Click&quot;</span> <span style="color: #008000;">/&gt;</span>
            <span style="color: #008000;">&lt;</span>br <span style="color: #008000;">/&gt;</span>
            <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Panel ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;fileUploadPanel&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
                <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>FileUpload ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;fileUpload&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> <span style="color: #008000;">/&gt;</span>
                <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Button ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;submitButton&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> Text<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Submit&quot;</span> 
                OnClick<span style="color: #008000;">=</span><span style="color: #666666;">&quot;submitButton_Click&quot;</span> <span style="color: #008000;">/&gt;</span>
            <span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>Panel<span style="color: #008000;">&gt;</span>
            <span style="color: #008000;">&lt;</span>br <span style="color: #008000;">/&gt;</span>
            <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Label ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;statusLabel&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> <span style="color: #008000;">/&gt;</span>
        <span style="color: #008000;">&lt;/</span>ContentTemplate<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>Triggers<span style="color: #008000;">&gt;</span>
            <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>AsyncPostBackTrigger ControlID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;showButton&quot;</span> <span style="color: #008000;">/&gt;</span>
            <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>PostBackTrigger ControlID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;submitButton&quot;</span> <span style="color: #008000;">/&gt;</span>
        <span style="color: #008000;">&lt;/</span>Triggers<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>UpdatePanel<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>form<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>body<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>html<span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p>Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://techencoder.com/index.php/2009/02/fixing-fileupload/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>How to run JavaScript prior to System.Web.UI.Timer OnTick</title>
		<link>http://techencoder.com/index.php/2009/01/javascript-and-timer-ontick/</link>
		<comments>http://techencoder.com/index.php/2009/01/javascript-and-timer-ontick/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 07:07:34 +0000</pubDate>
		<dc:creator>r.claypool</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[StackOverflow]]></category>
		<category><![CDATA[Timer]]></category>
		<category><![CDATA[UpdatePanel]]></category>

		<guid isPermaLink="false">http://techencoder.com/?p=156</guid>
		<description><![CDATA[The short answer: you can&#8217;t &#8230; or at least not easily, but there is a better way. Let&#8217;s say you have a page that needs to post back every x minutes. In my case, I needed to implement an auto-save feature that the client requested. Saving the data would happen server side so I just [...]]]></description>
			<content:encoded><![CDATA[<p>The short answer: <em>you can&#8217;t</em> &#8230; or at least not easily, but there <em>is</em> a better way.</p>
<p>Let&#8217;s say you have a page that needs to post back every x minutes.  In my case, I needed to implement an auto-save feature that the client requested.  Saving the data would happen server side so I just used a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.timer.aspx" target="_blank">Timer</a> to initiate regular post backs.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ Page Language<span style="color: #008000;">=</span><span style="color: #666666;">&quot;C#&quot;</span> <span style="color: #008000;">%&gt;</span>
<span style="color: #008000;">&lt;</span>script runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Timer1_OnTick<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Last Postback: &quot;</span> <span style="color: #008000;">+</span> DateTime.<span style="color: #0000FF;">Now</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #008000;">&lt;/</span>script<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>html xmlns<span style="color: #008000;">=</span><span style="color: #666666;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>head id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Head1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>title<span style="color: #008000;">&gt;&lt;/</span>title<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>head<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>body<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>form id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;form1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>ScriptManager ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;sm&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> <span style="color: #008000;">/&gt;</span>
        <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Timer ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Timer1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> 
                OnTick<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Timer1_OnTick&quot;</span> Interval<span style="color: #008000;">=</span><span style="color: #666666;">&quot;4000&quot;</span> <span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;/</span>form<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>body<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>html<span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p>The problem surfaced when they also wanted a client-side prompt to allow or cancel the auto post back.  <strong>System.Web.UI.Timer does not have any client side events exposed, </strong> so I searched the web and asked our friends over at StackOverflow <a href="http://stackoverflow.com/questions/439677/how-to-run-javascript-prior-to-system-web-ui-timer-ontick" target="_blank">what they would do</a>.</p>
<p>The only response to my post confirmed that the Timer is a bad fit for this situation.  I could hack it, but <em>there must be a better way.</em></p>
<div id="attachment_170" class="wp-caption alignleft" style="width: 610px"><img src="http://techencoder.com/wp-content/uploads/2009/01/square-peg-in-a-round-hole.png" alt="Square Peg in a Round Hole" title="square-peg-in-a-round-hole" width="350" height="190" class="size-full wp-image-170" /><p class="wp-caption-text">Square Peg in a Round Hole</p></div>
<p>Instead of using a Timer to initiate post backs, I switched to a combination of setTimeout() and __doPostBack().  It&#8217;s pure html and JavaScript goodness!  </p>
<p>In this example, I added an update panel to demonstrate how __doPostBack() can also be used to create a partial post back (leaving some parts of the page unchanged after the auto post back).  That is not necessary, but if you are posting back to the server automatically, an AJAX experience will probably be better for the user.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ Page Language<span style="color: #008000;">=</span><span style="color: #666666;">&quot;C#&quot;</span> <span style="color: #008000;">%&gt;</span>
<span style="color: #008000;">&lt;</span>script runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>Page.<span style="color: #0000FF;">IsPostBack</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">string</span> time <span style="color: #008000;">=</span> DateTime.<span style="color: #0000FF;">Now</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">insidePanelLabel</span>.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Last Postback: &quot;</span> <span style="color: #008000;">+</span> time<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">outsidePanelLabel</span>.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;blah blah&quot;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Does not show up after partial post back.</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #008000;">&lt;/</span>script<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>html xmlns<span style="color: #008000;">=</span><span style="color: #666666;">&quot;http://www.w3.org/1999/xhtml&quot;</span><span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>head id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Head1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>title<span style="color: #008000;">&gt;&lt;/</span>title<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>script type<span style="color: #008000;">=</span><span style="color: #666666;">&quot;text/javascript&quot;</span> language<span style="color: #008000;">=</span><span style="color: #666666;">&quot;javascript&quot;</span><span style="color: #008000;">&gt;</span>
        window.<span style="color: #0000FF;">onload</span> <span style="color: #008000;">=</span> function<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// start the auto postback timer.</span>
            setPostbackTimer<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">8</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        function setPostbackTimer<span style="color: #000000;">&#40;</span>seconds<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            window.<span style="color: #0000FF;">setTimeout</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;conditionalPostback()&quot;</span>, seconds <span style="color: #008000;">*</span> <span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        function canContinue<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> confirm<span style="color: #000000;">&#40;</span><span style="color: #666666;">'The page is requesting new data.  Ok or Cancel?'</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
        function conditionalPostback<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>canContinue<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// User permits the postback. </span>
                <span style="color: #008080; font-style: italic;">// Do it.</span>
                __doPostBack<span style="color: #000000;">&#40;</span><span style="color: #666666;">'UpdatePanel1'</span>, <span style="color: #666666;">''</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">else</span> <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// User denied the postback. </span>
                <span style="color: #008080; font-style: italic;">// Reset the timer (they will be prompted again).</span>
                setPostbackTimer<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">8</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #008000;">&lt;/</span>script<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>head<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>body<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>form id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;form1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>ScriptManager ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;sm&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> <span style="color: #008000;">/&gt;</span>
        <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>UpdatePanel ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;UpdatePanel1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
            <span style="color: #008000;">&lt;</span>ContentTemplate<span style="color: #008000;">&gt;</span>
                <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Label ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;insidePanelLabel&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> 
                    Text<span style="color: #008000;">=</span><span style="color: #666666;">&quot;This text will change during auto postbacks.&quot;</span><span style="color: #008000;">/&gt;</span>
            <span style="color: #008000;">&lt;/</span>ContentTemplate<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>UpdatePanel<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>br <span style="color: #008000;">/&gt;</span>
        <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Label ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;outsidePanelLabel&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> 
            Text<span style="color: #008000;">=</span><span style="color: #666666;">&quot;This text will not change during auto postbacks.&quot;</span><span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;/</span>form<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>body<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>html<span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p><strong>Have you ever tried to make Microsoft controls fit into a situation only to find that plain html and JavaScript are a better fit?</strong>  </p>
<p>The WebForms model often leads me to over rely on controls and I forget that plain html and JavaScript solutions are available too.  Using controls is fine, but think twice if you have to hack them to get what you want.  There is probably a better way.</p>
<p>Happy coding.</p>
]]></content:encoded>
			<wfw:commentRss>http://techencoder.com/index.php/2009/01/javascript-and-timer-ontick/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
