<?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>Quickduck &#187; Asp.Net</title>
	<atom:link href="http://quickduck.com/blog/category/development/net/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://quickduck.com/blog</link>
	<description>Straight from the mind of geniuseseses....</description>
	<lastBuildDate>Wed, 20 Jan 2010 07:52:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Path resolution in ASP.NET</title>
		<link>http://quickduck.com/blog/2010/01/14/path-resolution-in-asp-net/</link>
		<comments>http://quickduck.com/blog/2010/01/14/path-resolution-in-asp-net/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 14:15:20 +0000</pubDate>
		<dc:creator>Gerrod</dc:creator>
				<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://quickduck.com/blog/?p=249</guid>
		<description><![CDATA[One thing I&#8217;ve always thought that ASP.NET doesn&#8217;t do a great job of is handling resource paths. For example, lets say on your development box, you have a website hosted under the virtual directory &#8220;MyProject&#8221;, such that you browse to http://localhost/MyProject/ to go to the home page. Lets also say that when you deploy the [...]]]></description>
			<content:encoded><![CDATA[<p>One thing I&#8217;ve always thought that ASP.NET doesn&#8217;t do a great job of is handling resource paths. For example, lets say on your development box, you have a website hosted under the virtual directory &#8220;MyProject&#8221;, such that you browse to <span style="font-family:courier">http://localhost/MyProject/</span> to go to the home page. Lets also say that when you deploy the website to an external domain, it falls into the domain root, so instead you go to <span style="font-family:courier">http://myproject.com/</span> to see your home page.</p>
<p>Sound familiar? The real problem then comes when you try and define a resource (e.g. a javascript file) using a relative path:</p>
<pre class="brush: xml;">
&lt;script
    type=&quot;text/javascript&quot;
    src=&quot;/Scripts/jquery.js&quot;&gt;
</pre>
<p>This will work fine and dandy when you deploy the website, however on your local machine it will be looking for jquery at the path <span style="font-family:courier">http://localhost/Scripts/jquery.js&#8221;</span> &#8211; which more than likely isn&#8217;t going to work.</p>
<p>To get around this problem, I wrote a quick helper method called &#8220;Locate&#8221;, which I find myself reusing time and time again between websites. More often than not, I put it into a static class called &#8220;SiteManager&#8221; which basically just contains a bunch of helper functions relevant to the current website. Here&#8217;s the method:</p>
<pre class="brush: csharp;">
/// &lt;summary&gt;
/// Resolves the path to a URL
/// &lt;/summary&gt;
/// &lt;param name=&quot;url&quot;&gt;The path to be resolved, relative to the
/// application root&lt;/param&gt;
/// &lt;param name=&quot;formatArgs&quot;&gt;String formatting arguments&lt;/param&gt;
/// &lt;returns&gt;The URL&lt;/returns&gt;
static public string Locate(string url, params object[] formatArgs)
{
    if (String.IsNullOrEmpty(url))
        url = &quot;/&quot;;

    if (formatArgs != null &amp;&amp; formatArgs.Length &gt; 0)
        url = String.Format(url, formatArgs);

    HttpContext context = HttpContext.Current;
    return String.Concat(
        context.Request.ApplicationPath,
        !url.StartsWith(&quot;/&quot;) ? &quot;/&quot; : String.Empty,
        url);
}
</pre>
<p>To use the method, you simply change your script declaration (or whatever resource you&#8217;re trying to find) as follows:</p>
<pre class="brush: csharp; html-script: true;">
&lt;script
    type=&quot;text/javascript&quot;
    src=&quot;&lt;%= SiteManager.Locate(&quot;/Scripts/jquery.js&quot;) %&gt;&quot;&gt;
&lt;/script&gt;
</pre>
<p>You&#8217;ll also notice that it supports string formatting &#8211; so even though it would be pointless in this particular example, you could, if you preferred, do something like this:</p>
<pre class="brush: csharp; html-script: true;">
&lt;script
    type=&quot;text/javascript&quot;
    src=&quot;&lt;%= SiteManager.Locate(&quot;/Scripts/{0}.js&quot;, &quot;jquery&quot;) %&gt;&quot;&gt;
&lt;/script&gt;
</pre>
<p>In both instances, this will resolve the URL in your output document using the current application path &#8211; </p>
<ul>
<li><span style="font-family:courier">http://localhost/MyProject/Scripts/jquery.js</span> on your local machine; and</li>
<li><span style="font-family:courier">http://myproject.com/Scripts/jquery.js</span> on the web server.</li>
</ul>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://quickduck.com/blog/2010/01/14/path-resolution-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Containing floats in HTML</title>
		<link>http://quickduck.com/blog/2009/11/27/containing-floats-in-html/</link>
		<comments>http://quickduck.com/blog/2009/11/27/containing-floats-in-html/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 14:46:30 +0000</pubDate>
		<dc:creator>Gerrod</dc:creator>
				<category><![CDATA[Asp.Net]]></category>

		<guid isPermaLink="false">http://quickduck.com/blog/?p=219</guid>
		<description><![CDATA[Have you ever created a block-level element (e.g. a div), whose only contents are floating elements &#8211; only to find that your block-level element doesn&#8217;t stretch down to contain it&#8217;s children? Well, I have, and it&#8217;s a problem that always annoys me because I can never bring to mind the easiest way of fixing it.
The [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever created a block-level element (e.g. a div), whose only contents are floating elements &#8211; only to find that your block-level element doesn&#8217;t stretch down to contain it&#8217;s children? Well, I have, and it&#8217;s a problem that always annoys me because I can never bring to mind the easiest way of fixing it.</p>
<p>The simplest solution is to use &#8220;overflow:hidden&#8221; in the style of your parent element, however this doesn&#8217;t work for all browsers scenarios. So, for a much more comprehensive description of the problem, as well as a number of approaches you can use to solve it, check out <a href="http://www.ejeliot.com/blog/59">this post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://quickduck.com/blog/2009/11/27/containing-floats-in-html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What Is a Race Condition?</title>
		<link>http://quickduck.com/blog/2009/10/06/what-is-a-race-condition/</link>
		<comments>http://quickduck.com/blog/2009/10/06/what-is-a-race-condition/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 09:13:44 +0000</pubDate>
		<dc:creator>Drew</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://quickduck.com/blog/?p=188</guid>
		<description><![CDATA[Just thought I would put a post out on something I learnt today that can occur when using ajax- a race condition. A race condition is is where the output or result of something is dependent on the timing of other events/code. A good example of this is below:

function ValidateInput() {
//some slow running code here...
}

function [...]]]></description>
			<content:encoded><![CDATA[<p>Just thought I would put a post out on something I learnt today that can occur when using ajax- a race condition. A <a href="http://en.wikipedia.org/wiki/Race_condition" target="_blank">race condition</a> is is where the output or result of something is dependent on the timing of other events/code. A good example of this is below:</p>
<pre class="brush: jscript;">
function ValidateInput() {
//some slow running code here...
}

function SaveForm() {
//save the form
}
</pre>
<pre class="brush: xml;">

&lt;form&gt;
&lt;input type=&quot;text&quot; onchange=&quot;ValidateInput()&quot; /&gt;
&lt;input type=&quot;button&quot; onclick=&quot;SaveForm();&quot; value=&quot;Submit&quot; /&gt;
&lt;/form&gt;
</pre>
<p>The problem here can occur when the user hits the Submit button before the validation method can finish. One way to overcome this is use a <a title="Semaphore" href="http://en.wikipedia.org/wiki/Semaphore_%28programming%29" target="_blank">semaphore</a> to indicate whether the form still needs validating on the SaveForm method.</p>
]]></content:encoded>
			<wfw:commentRss>http://quickduck.com/blog/2009/10/06/what-is-a-race-condition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;m back</title>
		<link>http://quickduck.com/blog/2008/10/30/im-back/</link>
		<comments>http://quickduck.com/blog/2008/10/30/im-back/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 07:06:02 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://quickduck.com/blog/2008/10/30/im-back/</guid>
		<description><![CDATA[After having 9 months off from doing .net (travelling, bumming and then a 3 month contract role as an architect in a coldfusion shop) I finally got myself a role doing what I love doing best &#8211; playing with .net and c#.
In the last 4 weeks I&#8217;ve been researching and prototyping apps that use

.net 3.5
ado.net [...]]]></description>
			<content:encoded><![CDATA[<p>After having 9 months off from doing .net (travelling, bumming and then a 3 month contract role as an architect in a coldfusion shop) I finally got myself a role doing what I love doing best &#8211; playing with .net and c#.</p>
<p>In the last 4 weeks I&#8217;ve been researching and prototyping apps that use</p>
<ul>
<li>.net 3.5</li>
<li><a href="http://en.wikipedia.org/wiki/ADO.NET_Entity_Framework">ado.net entity framework</a></li>
<li><a href="http://msdn.microsoft.com/en-us/data/bb931106.aspx">ado.net data services</a> &#8211; including .net, ajax and silverlight client libraries</li>
<li><a href="http://silverlight.net">Silverlight 2.0</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/ms364077(VS.80).aspx">Visual Studio for Software Testers &#8211; Web Testing</a></li>
</ul>
<p>It&#8217;s been awesome to have the time and resources to touch across all of these technologies to enjoy their benefits and to loath the limitations.</p>
<p>All in all I reckon all of the technologies are a great addition to the .net stack and look forward to seeing them mature with each new release.</p>
<p>I look forward to documenting my findings as I find time to re-work them into don&#8217;t-give-away-IP examples.</p>
]]></content:encoded>
			<wfw:commentRss>http://quickduck.com/blog/2008/10/30/im-back/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Alternating items without using an AlternatingItemTemplate</title>
		<link>http://quickduck.com/blog/2008/08/27/alternating-items-without-using-an-alternatingitemtemplate/</link>
		<comments>http://quickduck.com/blog/2008/08/27/alternating-items-without-using-an-alternatingitemtemplate/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 08:06:57 +0000</pubDate>
		<dc:creator>Gerrod</dc:creator>
				<category><![CDATA[Asp.Net]]></category>

		<guid isPermaLink="false">http://quickduck.com/blog/2008/08/27/alternating-items-without-using-an-alternatingitemtemplate/</guid>
		<description><![CDATA[Many of the controls in ASP.Net (e.g. a Repeater) support the concept of an AlternatingItemTemplate, which, as the name suggests, allows you to define an additional item template to change the look and feel for each alternating item in the data source. This is all well and good, but I&#8217;ve never seen a good use [...]]]></description>
			<content:encoded><![CDATA[<p>Many of the controls in ASP.Net (e.g. a Repeater) support the concept of an AlternatingItemTemplate, which, as the name suggests, allows you to define an additional item template to change the look and feel for each alternating item in the data source. This is all well and good, but I&#8217;ve never seen a <i>good</i> use for it; more often than not, all you really want to do in your alternating item is, for example, slightly change the background colour for ease of visual differentiation.</p>
<p>Though you <i>can</i> use the alternating item template for this, it typically involves you duplicating a lot of code, since the AlternatingItemTemplate is mostly the same as your ItemTemplate (save perhaps for a CSS class declaration somewhere).</p>
<pre><code>
  &lt;asp:Repeater ID="rpt" runat="server"&gt;
      &lt;HeaderTemplate&gt;
          &lt;table cellpadding="0" cellspacing="0"&gt;
              &lt;tr&gt;
                  &lt;th&gt;First Name&lt;/th&gt;
                  &lt;th&gt;Last Name&lt;/th&gt;
                  &lt;th&gt;Age&lt;/th&gt;
              &lt;/tr&gt;
       &lt;/HeaderTemplate&gt;
       &lt;ItemTemplate&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;%# Eval("FirstName") %&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;%# Eval("LastName") %&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;%# Eval("Age") %&gt;&lt;/td&gt;
              &lt;/tr&gt;
       &lt;/ItemTemplate&gt;
       &lt;AlternatingItemTemplate&gt;
              &lt;tr class="Alternating"&gt;
                  &lt;td&gt;&lt;%# Eval("FirstName") %&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;%# Eval("LastName") %&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;%# Eval("Age") %&gt;&lt;/td&gt;
              &lt;/tr&gt;
       &lt;/AlternatingItemTemplate&gt;
       &lt;FooterTemplate&gt;
          &lt;/table&gt;
       &lt;/FooterTemplate&gt;
  &lt;/asp:Repeater&gt;
</code></pre>
<p>If this sounds like you, then never fear &#8211; <i>there IS a better way</i>!</p>
<p>When you&#8217;re binding, you have access to the RepeaterItem via the Container property, which contains an ItemIndex property. As such, the simplest way of alternating your items is simply to check if the number divides evenly by two:</p>
<pre><code>
  &lt;asp:Repeater ID="rpt" runat="server"&gt;
      &lt;HeaderTemplate&gt;
          &lt;table cellpadding="0" cellspacing="0"&gt;
              &lt;tr&gt;
                  &lt;th&gt;First Name&lt;/th&gt;
                  &lt;th&gt;Last Name&lt;/th&gt;
                  &lt;th&gt;Age&lt;/th&gt;
              &lt;/tr&gt;
       &lt;/HeaderTemplate&gt;
       &lt;ItemTemplate&gt;
              &lt;tr class="&lt;%# Container.ItemIndex % 2 == 0 ? "Alternating" : String.Empty %&gt;"&gt;
                  &lt;td&gt;&lt;%# Eval("FirstName") %&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;%# Eval("LastName") %&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;%# Eval("Age") %&gt;&lt;/td&gt;
              &lt;/tr&gt;
       &lt;/ItemTemplate&gt;
       &lt;FooterTemplate&gt;
          &lt;/table&gt;
       &lt;/FooterTemplate&gt;
  &lt;/asp:Repeater&gt;
</code></pre>
<p>There is a minor downside using this approach &#8211; the non-alternating rows will all declare an empty CSS class within them. But, this is a sacrifice I think is acceptable to decrease repetition of code.</p>
]]></content:encoded>
			<wfw:commentRss>http://quickduck.com/blog/2008/08/27/alternating-items-without-using-an-alternatingitemtemplate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DataBinding with XPath</title>
		<link>http://quickduck.com/blog/2007/10/12/databinding-with-xpath/</link>
		<comments>http://quickduck.com/blog/2007/10/12/databinding-with-xpath/#comments</comments>
		<pubDate>Fri, 12 Oct 2007 12:31:58 +0000</pubDate>
		<dc:creator>Gerrod</dc:creator>
				<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://quickduck.com/blog/?p=44</guid>
		<description><![CDATA[Did you know that when you bind an item to a DataBound control (e.g. a repeater), you can use the XPath function to evaluate&#8230; well, an XPath? Obviously this is only going to work if you bind an XmlNode (or subclass) instance to the control, but still &#8211; comes in very handy!

// in code-behind
rpt.DataSource = [...]]]></description>
			<content:encoded><![CDATA[<p>Did you know that when you bind an item to a DataBound control (e.g. a repeater), you can use the XPath function to evaluate&#8230; well, an XPath? Obviously this is only going to work if you bind an XmlNode (or subclass) instance to the control, but still &#8211; comes in very handy!</p>
<pre><code>
// in code-behind
rpt.DataSource = document.SelectNodes("/ROOT/students/student");
rpt.DataBind();
</code></pre>
<pre><code>
&lt;!-- in aspx page --&gt;
&lt;asp:Repeater id="rpt" runat="server"&gt;
    &lt;ItemTemplate&gt;
        &lt;%# XPath("name/text()") %&gt;
    &lt;/ItemTemplate&gt;
&lt;/asp:Repeater&gt;
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://quickduck.com/blog/2007/10/12/databinding-with-xpath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ibox, Prototype, and JSON</title>
		<link>http://quickduck.com/blog/2007/08/02/ibox-prototype-and-json/</link>
		<comments>http://quickduck.com/blog/2007/08/02/ibox-prototype-and-json/#comments</comments>
		<pubDate>Thu, 02 Aug 2007 08:26:23 +0000</pubDate>
		<dc:creator>Gerrod</dc:creator>
				<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://quickduck.com/blog/?p=38</guid>
		<description><![CDATA[In my current project, I&#8217;m doing some fancy-pants stuff to lookup UK addresses via a web service, then send them to the client using JSON. On the client end, I&#8217;m displaying the results in an ibox and then sending the results back to the main form. Woah!
The first challenge was getting the ibox to open [...]]]></description>
			<content:encoded><![CDATA[<p>In my current project, I&#8217;m doing some fancy-pants stuff to lookup UK addresses via a web service, then send them to the client using JSON. On the client end, I&#8217;m displaying the results in an <a href="http://www.ibegin.com/blog/p_ibox.html" target="_blank">ibox</a> and then sending the results back to the main form. Woah!</p>
<p>The first challenge was getting the ibox to open and display the form correctly. I chose to use a hidden div as my &#8220;form&#8221;, and let the ibox display it on the screen when appropriate. It all seemed to work correctly, however when I tried to read the values out of the fields on the ibox form, it kept telling me they were empty!</p>
<p>After a lot of mucking around, cursing, and rude gestures directed at the computer &#8211; you know, the standard debugging drill &#8211; I worked out that when you use a hidden div as your ibox, it actually *clones* the entire InnerHTML of the hidden div! So in effect, you get *two* of every field with duplicate IDs. And, since the HTML generated by ibox goes at the *end* of your document, when you call document.getElementById, you get back the *first matching element*, which will always be the one that&#8217;s still safely hidden away in your form. Handy &#8211; not!!</p>
<p>But never fear, the solution is actually quite simple. You just have to create an external file containing your ibox form, and then use that as the HREF in your link:</p>
<pre><code>
&lt;a href="FindAddress.aspx" rel="ibox&#038;height=400" title="Find an address"&gt;Find address&lt;/a&gt;
</code></pre>
<p>Ahh, finally things started working properly! So now that I could read the postcode that the user entered, I wanted to hit a handler to&#8230;. err&#8230; &#8220;handle&#8221; the web service request. To do that, I used <a href="http://www.prototypejs.org/" target="_blank">prototype.js</a> &#8211; a javascript library with a whole bunch of wicked cool functionality (all of which is way beyond the scope of this article). Check it out -to execute a cross browser friendly AJAX request, you simply do this:</p>
<pre><code>
  var url = "Handlers/FindAddressHandler.ashx?Id=" + id;
  new Ajax.Request(url, {
    onSuccess: OnAddressFound,
    onFailure: OnError
  });
</code></pre>
<p>Of course, you can inline the callback functions, but I wanted to separate them for readability. Anyway, the next part was setting up the FindAddressHandler. I won&#8217;t go into too much detail here as it&#8217;s just a standard implementation of IHttpHandler which then hits a web service. The part I want to talk about though is writing back the address object using JSON. A dude named Jason Newton King has written a brilliant library called <a href="http://www.newtonsoft.com/blog/archive/2006/06/26/571.aspx" target="_blank">Json.NET</a> which makes life a hell of a lot easier!
<p>Basically, you just have to create a JsonWriter, then serialise the properties of your object that you want to send back to the client. So in my case with an Address object (stored in local variable &#8220;address&#8221;):</p>
<pre><code>
StringBuilder builder = new StringBuilder();
using (JsonWriter writer = new JsonWriter(new StringWriter(builder))) {
  writer.WriteStartObject();
  writer.WritePropertyName("PostCode");
  writer.WriteValue(address.Postcode);
  writer.WritePropertyName("Address1");
  writer.WriteValue(address.Line1);
  writer.WritePropertyName("Address2");
  writer.WriteValue(address.Line2);
  writer.WritePropertyName("Address3");
  writer.WriteValue(address.Line3);
  writer.WritePropertyName("PostalTown");
  writer.WriteValue(address.PostTown);
  writer.WriteEndObject();

  writer.Flush();
}

_context.Response.AddHeader("X-JSON", builder.ToString());
</code></pre>
<p>Easy, right? So the thing to note here, besides how simple it is to persist your object in JSON, is that I&#8217;m sending back the JSON string in a response header called &#8220;X-JSON&#8221;. Now back on the client side again &#8211; one of the bonus features of Prototype is that it automatically interprets whatever is in the &#8220;X-JSON&#8221; header, and builds your objects for you! So, here&#8217;s the code I wrote for my client-side callback:</p>
<pre><code>
function OnAddressFound(transport, address) {
    $("txtAddress1").value = address.Address1;
    $("txtAddress2").value = address.Address2;
    $("txtAddress3").value = address.Address3;
    $("txtPostCode").value = address.PostCode;
    $("txtPostalTown").value = address.PostalTown;

    hideIbox();
}
</code></pre>
<p>The first argument &#8211; transport &#8211; is the XmlHttpRequest object which was used. (You can find a great document which outlines the properties of the XmlHttpRequest object on the <a href="http://developer.apple.com/internet/webcontent/xmlhttpreq.html" target="_blank">Apple Developer Connection</a> website). The second argument is the object which Prototype interpreted from the X-JSON response header. You can see also that prototype implements a function &#8211; $ &#8211; which is effectively a suped-up version of document.getElementById.</p>
<p> Using all of these technologies together was surprisingly easy! I&#8217;m super impressed with how you can grab so many rich frameworks to enhance your websites, all for free!</p>
]]></content:encoded>
			<wfw:commentRss>http://quickduck.com/blog/2007/08/02/ibox-prototype-and-json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Skipping the Header in ItemDataBound</title>
		<link>http://quickduck.com/blog/2007/07/31/skipping-the-header-in-itemdatabound/</link>
		<comments>http://quickduck.com/blog/2007/07/31/skipping-the-header-in-itemdatabound/#comments</comments>
		<pubDate>Tue, 31 Jul 2007 10:28:21 +0000</pubDate>
		<dc:creator>Gerrod</dc:creator>
				<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://quickduck.com/blog/?p=37</guid>
		<description><![CDATA[I often subscribe to the ItemDataBound event in a repeater to perform custom logic for each item within the repeater (for example, performing some custom calculations). When the repeater includes a header though, more often than not, you want to skip over the header row, since you don&#8217;t want to perform your custom calculations on [...]]]></description>
			<content:encoded><![CDATA[<p>I often subscribe to the ItemDataBound event in a repeater to perform custom logic for each item within the repeater (for example, performing some custom calculations). When the repeater includes a header though, more often than not, you want to skip over the header row, since you don&#8217;t want to perform your custom calculations on that row. Until now, the way I did this was like this:</p>
<pre><code>
private void OnItemDataBound(object sender, RepeaterItemEventArgs e) {
    // skip header row
    if (e.Item.ItemIndex < 0) {
        return;
    }

    // custom logic
}
</code></pre>
<p>Today however, I found out there's a nicer way:</p>
<pre><code>
private void OnItemDataBound(object sender, RepeaterItemEventArgs e) {
    // skip header row
    if (e.Item.ItemType == ListItemType.Header) {
        return;
    }

    // custom logic
}
</code></pre>
<p>Sure, given that both ways work equally well, it seems as though the difference is for aesthetics only (i.e it's nicer to read); but there are actually two other big advantages:</p>
<ol>
<li>It is not tied into the implementation of the repeater - that is, it does not rely on the header row index being less than zero; and</li>
<li>You can use the ListItemType enumeration to detect many different types of items - for example, the Footer row for performing summary calculations.</li>
</ol>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://quickduck.com/blog/2007/07/31/skipping-the-header-in-itemdatabound/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internet Explorer script tag failure for valid xhtml</title>
		<link>http://quickduck.com/blog/2007/01/11/internet-explorer-script-tag-failure-for-valid-xhtml/</link>
		<comments>http://quickduck.com/blog/2007/01/11/internet-explorer-script-tag-failure-for-valid-xhtml/#comments</comments>
		<pubDate>Thu, 11 Jan 2007 14:54:29 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://quickduck.com/blog/?p=18</guid>
		<description><![CDATA[Boy, what a day!
I was working on the weirdest bug with a colleague today where we were receiving a javascript &#8220;Object expected&#8221; error when we migrated a page into our new ASP .Net Master Page format.
We thought we hadn&#8217;t made any breaking changes, all we had done was move the &#60;script&#62; tags into the MasterPage [...]]]></description>
			<content:encoded><![CDATA[<p>Boy, what a day!</p>
<p>I was working on the weirdest bug with a colleague today where we were receiving a javascript &#8220;Object expected&#8221; error when we migrated a page into our new ASP .Net Master Page format.</p>
<p>We thought we hadn&#8217;t made any breaking changes, all we had done was move the &lt;script&gt; tags into the MasterPage file from the content page.</p>
<p>That didn&#8217;t work, so we created a header content place holder in the master page &lt;head&gt; element and in the content page put back the &lt;script&gt; includes. That didn&#8217;t work either.</p>
<p>We then included the &lt;script&gt; tags in both the master and content page. That seemed to work. Very odd.</p>
<p>In the end after many attempts to figure out what was going wrong, we found the problem was with how MSIE parses &lt;script&gt; tags, it cannot use self closing tags or an empty element &#8211; ie. &lt;script &#8230; /&gt;.</p>
<p>It <strong>has</strong> to have the &lt;script>&lt;/script&gt; tag.</p>
<p>For more info check out <a href="http://www.quirksmode.org/bugreports/archives/2006/06/MSIE_script_tag_failure_in_valid_xhtml.html" target="_blank">quirksmode.org</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://quickduck.com/blog/2007/01/11/internet-explorer-script-tag-failure-for-valid-xhtml/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sql timeout &#8211; a trap for young players!</title>
		<link>http://quickduck.com/blog/2006/12/22/sql-timeout-a-trap-for-young-players/</link>
		<comments>http://quickduck.com/blog/2006/12/22/sql-timeout-a-trap-for-young-players/#comments</comments>
		<pubDate>Fri, 22 Dec 2006 18:57:56 +0000</pubDate>
		<dc:creator>Gerrod</dc:creator>
				<category><![CDATA[Asp.Net]]></category>
		<category><![CDATA[Sql Server]]></category>

		<guid isPermaLink="false">http://quickduck.com/blog/?p=17</guid>
		<description><![CDATA[I was talking to one of the guys at work about Sql timeouts. He had a long running operation &#8211; about 40 seconds &#8211; so to compensate for this, he set the timeout on his connection string to one minute:

&#60;connectionStrings&#62;
  &#60;add name="cs"
    connectionString="Data Source=localhost;Initial Catalog=MyDB;Connection Timeout=60;"
&#60;/connectionStrings&#62;

Sure looks OK, but as it [...]]]></description>
			<content:encoded><![CDATA[<p>I was talking to one of the guys at work about Sql timeouts. He had a long running operation &#8211; about 40 seconds &#8211; so to compensate for this, he set the timeout on his connection string to one minute:</p>
<pre><code>
&lt;connectionStrings&gt;
  &lt;add name="cs"
    connectionString="Data Source=localhost;Initial Catalog=MyDB;Connection Timeout=60;"
&lt;/connectionStrings&gt;
</code></pre>
<p>Sure looks OK, but as it turns out, this wasn&#8217;t working for him. The reason is actually quite straightforward &#8211; the <b>Connection Timeout</b> property is used to specify how long the application will wait to <i>establish</i> a connection to the server before giving up and throwing an exception. In most cases (where connections are properly managed), the connection will be returned almost instantaneously, hence changing this value is usually not required.</p>
<p>Instead, the timeout that he needed to change was the <b>CommandTimeout</b> on the SqlCommand object which was being passed to the database.</p>
<pre><code>
  SqlCommand command = new SqlCommand();
  command.CommandTimeout = 60;
</pre>
<p></code></p>
<p>As the MSDN doco states, this property "Gets or sets the wait time before terminating the attempt to execute a command and generating an error". And sure enough, once he changed this value to 60, everything was dandy.</p>
]]></content:encoded>
			<wfw:commentRss>http://quickduck.com/blog/2006/12/22/sql-timeout-a-trap-for-young-players/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
