<?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>Uzair's Weblog &#187; .NET</title>
	<atom:link href="http://uzair.nairang.org/articles/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://uzair.nairang.org</link>
	<description>Where Uzairs Roam</description>
	<lastBuildDate>Sun, 30 May 2010 12:53:20 +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>Excel Tools: TidyArray</title>
		<link>http://uzair.nairang.org/articles/2010/05/30/excel-tools-tidyarray/</link>
		<comments>http://uzair.nairang.org/articles/2010/05/30/excel-tools-tidyarray/#comments</comments>
		<pubDate>Sun, 30 May 2010 12:53:20 +0000</pubDate>
		<dc:creator>Uzair</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Geekistry]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://uzair.nairang.org/?p=373</guid>
		<description><![CDATA[GB at DKIB put together an absolutely fantastic Excel interface for our analytics. A lot of the functionality is probably industry standard at this point, but the quality of GB&#8217;s tools was absolutely fantastic, and there were aesthetic touches that really made it a pleasure to use.

One tool that I hadn&#8217;t seen before but have [...]]]></description>
			<content:encoded><![CDATA[<p>GB at DKIB put together an absolutely fantastic Excel interface for our analytics. A lot of the functionality is probably industry standard at this point, but the quality of GB&#8217;s tools was absolutely fantastic, and there were aesthetic touches that really made it a pleasure to use.</p>

<p>One tool that I hadn&#8217;t seen before but have since come to rely on was an innocuous looking button with the label &#8216;Tidy Array&#8217; that would resize an Excel range with an array formula in it. This is probably the biggest PITA in Excel: entering a formula that returns several values. However, unless you know exactly how many values the formula is going to return, you&#8217;re left either getting only part of the result back, or with unsightly #N/As framing the result. Tidy Array would evaluate the formula internally, check the size of the returned result, resize the range in which the formula had been entered, and then re-evaluate the formula to fill that resized range with the result.</p>

<p>Since leaving DKIB, I&#8217;ve been playing around with <a href="http://exceldna.codeplex.com/">ExcelDNA</a>, Govert van Drimmelen&#8217;s fantastic library for building XLLs in managed code, to build an Excel-based interface for my trading system. I missed Tidy Array, so I put something similar together (link below). It&#8217;s a little different in that after you run the function (from the &#8216;Pandora&#8217; menu), it just resizes the selected range to the correct size rather than filling that resized range; the reason for this is that this prevents neighbouring cells from being inadvertently overwritten. (Note: GB&#8217;s version had logic to keep it from overwriting stuff, but I prefer to limit function behaviour rather than add behind-the-scenes logic.)</p>

<p>I tried to add a keyboard shortcut for it too (Ctrl + Shift + T) but I haven&#8217;t managed to get it to work yet.</p>

<p><strong>To use:</strong></p>

<ol>
<li>Unzip to some convenient directory. Note the location of the TidyArray.xll file.</li>
<li>Start Excel and add TidyArray.xll as an Excel Add-in (In 2003, it&#8217;s under Tools -> Addins; in 2007, it&#8217;s under Excel Options -> Add-ins -> Excel Add-ins</li>
</ol>

<p><a href='http://uzair.nairang.org/wp-content/uploads/2010/05/TidyArray.zip'>TidyArray.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://uzair.nairang.org/articles/2010/05/30/excel-tools-tidyarray/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>VS.NET 2003 Find/Replace</title>
		<link>http://uzair.nairang.org/articles/2006/02/15/vs-net-2003-find-replace/</link>
		<comments>http://uzair.nairang.org/articles/2006/02/15/vs-net-2003-find-replace/#comments</comments>
		<pubDate>Wed, 15 Feb 2006 01:21:00 +0000</pubDate>
		<dc:creator>Uzair</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Geekistry]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[(This has been sitting in my Performancing extension for several weeks, so since I haven&#8217;t updated recently, might as well publish it.)I&#8217;ve just discovered that the regular expressions available through Find/Replace in VS.NET 2003 are not standard .NET/POSIX regular expressions. It seems curlies ({, }) specify tagged expressions. Unfortunately, this means one of the most [...]]]></description>
			<content:encoded><![CDATA[<p>(This has been sitting in my Performancing extension for several weeks, so since I haven&#8217;t updated recently, might as well publish it.)<br /><br />I&#8217;ve just discovered that the regular expressions available through Find/Replace in VS.NET 2003 are not standard .NET/POSIX regular expressions. It seems curlies (<code>{</code>, <code>}</code>) specify tagged expressions. Unfortunately, this means one of the most important elements in regular expressions, quantifiers, are simply not available.<br /><br />Quantifiers include the wildcards (<code>*</code>, <code>+</code> and <code>?</code>) most people are familiar with as well as the following constructs:<br /></p>

<ul><li>&nbsp;`{2}` &#8212; matches the preceding identifier twice</li><li>`{2,3}` &#8212; matches the preceding identifier between two and three times</li><li>`{2,}` &#8212; matches the preceding identifier at least twice<br /></li></ul>

<p><br />More reading is at MSDN&#8217;s <a href="http://msdn2.microsoft.com/en-us/library/2k3te2cs.aspx">Regular Expressions (Visual Studio)</a> and <a href="http://msdn2.microsoft.com/en-us/library/afy96z92.aspx">Wildcards (Visual Studio)</a> pages.<br /></p>
]]></content:encoded>
			<wfw:commentRss>http://uzair.nairang.org/articles/2006/02/15/vs-net-2003-find-replace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP .NET 2.0 and script.aculo.us</title>
		<link>http://uzair.nairang.org/articles/2005/10/30/asp-net-2-0-and-script-aculo-us/</link>
		<comments>http://uzair.nairang.org/articles/2005/10/30/asp-net-2-0-and-script-aculo-us/#comments</comments>
		<pubDate>Sun, 30 Oct 2005 17:12:00 +0000</pubDate>
		<dc:creator>Uzair</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Geekistry]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I&#8217;m having an absolutely awesome dicking around with script.aculo.us. For those who don&#8217;t know, script.aculo.us is a fabulous Javascript library built on Prototype to add a lot of cool AJAX functionality. Prototype ispretty tightly bound to Ruby-on-Rails, and apparently script.aculo.us is meandering down that route too. Massive shame &#8212; it really is quite nice, and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m having an absolutely awesome dicking around with <a href="http://script.aculo.us">script.aculo.us</a>. For those who don&#8217;t know, script.aculo.us is a fabulous Javascript library built on <a href="http://prototype.conio.net/">Prototype</a> to add a lot of cool AJAX functionality. Prototype ispretty tightly bound to Ruby-on-Rails, and apparently script.aculo.us is meandering down that route too. Massive shame &#8212; it really is quite nice, and it&#8217;s a shame that the lack of documentation and (to put it bluntly) championing of RoR as the end-all-be-all of web development is keeping it from the rest of the web dev community.</p>

<p>Anyway, since Atlas is a little ways off from being production-ready, I decided I&#8217;d see if I could put script.aculo.us to some use on my project (yes, the one with RI that I started many moons ago). I initially just wanted a quick solution for making some elements draggable, but since I discovered the <a href="http://script.aculo.us/demos/shop">shopping card demo</a>, I&#8217;ve become quite keen on bringing Droppables into the mix as well.</p>

<p>Unfortunately, as I mentioned above, there&#8217;s little to no documentation on how to actually use the library &#8212; the website will literally go no further than to show you some source code. <em>Ruby</em> source code. Brilliant.</p>

<p>Thankfully, Javascript is simple and obvious since you can choose to &#8216;view source&#8217; any website you come across.</p>

<p><strong>Creating Draggable objects</strong></p>

<p><code>Draggable</code> is the JS class that describes objects that can be dragged (mouse-down on them and move the mouse around). Here&#8217;s how to create a draggable object:</p>

<pre>
&lt;img id="image1" src="image.gif" /&gt;
&lt;script language="text/javascript"&gt;
new Draggable ('image1', {ghosting:true});&lt;script&gt;
</pre>

<p>The <code>ghosting</code> option makes the image translucent when it is being dragged. There are several other cool options, including <code>revert</code>, which is often used with Droppable objects to make the Draggable return to its original position on mouse-up. Of course, seemingly none of this is documented, and you have to go digging through the code to find them. You&#8217;ll notice that the inevitable call to <code>getElementById</code> is hidden and script.aculo.us accepts simply the element ID you want to manipulate. Nice touches like that win hearts.</p>

<p>To make one of my FormView&#8217;s draggable, I wrapped the <code>&lt;asp:FormView&gt;</code> tag in my <code>aspx</code> file in a <code>div</code> and gave it a convenient name, to prevent having to register the script (see my post about name mangling).</p>

<p>An important thing to note is that once you&#8217;ve made your element Draggable, it&#8217;s tricky to manipulate it with your own re-positioning code. For example, suppose you&#8217;ve got a Draggable that you also want to be able to reposition by clicking anywhere on the page. If you write your own scriptlet to do this, you run into all the problems associated with relative and absolute positioning. Not insurmountable, but there goes half an hour&#8230;</p>

<p><strong>Using Droppables</strong></p>

<p>Here&#8217;s a trickier problem. Like I mentioned, I thought the shopping cart demo was really cool, and I was very keen on doing something similar on my page. Unfortunately, the code available is pretty cryptic:</p>

<pre>
< %= drop_receiving_element "cart", 
      :update => "items", :url => { :action => "add" },
      :accept => "products", :hoverclass => "cart-active",
      :loading => "Element.show('indicator')",
      :complete => "Element.hide('indicator')" %>
</pre>

<p>This is translated to the Javascript below:</p>

<pre>
&lt;script type="text/javascript"&gt;
Droppables.add('cart', {accept:'products', onDrop:function(element){
  new Ajax.Updater('items', '/demos/shop/add',
  {onLoading:function(request){Element.show('indicator')}, 
  onComplete:function(request){Element.hide('indicator')}, 
  parameters:'id=' + encodeURIComponent(element.id), 
  evalScripts:true, asynchronous:true})}, hoverclass:'cart-active'})&lt;/script&gt;
</pre>

<p>Again, not easy to interpret: what exactly is the <code>add</code> page returning? Merely a count of the various elements the cart contains, or the actual HTML to represent the cart?</p>

<p>For the answer, one need only visit <code>http://script.aculo.us/demos/shop/add?id=item_2_0</code>. This is the actual URL the demo hits when you drop a t-shirt into the cart (that item ID is out of the page source) . You might need to visit the actual cart first and add a t-shirt to get the server-side bit set up properly &#8212; I ran into a &#8216;null array&#8217; exception when I tried it directly.</p>

<p>Hitting that URL shows that the <code>add</code> page is returning the full state of the shopping cart, serialized as HTML.</p>

<p>I haven&#8217;t gotten around to coding the equivalent ASP.NET yet, but it should be simple. Equally, given how cleanly the library interacts with HTML elements (eg. requiring only the element ID to be able to apply effects), it should be easy to use the other stuff provided.</p>
]]></content:encoded>
			<wfw:commentRss>http://uzair.nairang.org/articles/2005/10/30/asp-net-2-0-and-script-aculo-us/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.NET 2.0 name mangling</title>
		<link>http://uzair.nairang.org/articles/2005/10/14/asp-net-2-0-name-mangling/</link>
		<comments>http://uzair.nairang.org/articles/2005/10/14/asp-net-2-0-name-mangling/#comments</comments>
		<pubDate>Fri, 14 Oct 2005 16:50:00 +0000</pubDate>
		<dc:creator>Uzair</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Code mangling&#8217;s always been a problem with ASP .NET &#8212; the VS .NET 2002/2003 used to mangle the HTML badly when you switched between design and code views, and while that&#8217;s been fixed in VS .NET 2005 (aka, The-Shiznit-For-Web-Development-2005), there&#8217;s still the problem of element name mangling while rendering. So, for example, a FormView element [...]]]></description>
			<content:encoded><![CDATA[<p>Code mangling&#8217;s always been a problem with ASP .NET &#8212; the VS .NET 2002/2003 used to mangle the HTML badly when you switched between design and code views, and while that&#8217;s been fixed in VS .NET 2005 (aka, The-Shiznit-For-Web-Development-2005), there&#8217;s still the problem of element name mangling while rendering. So, for example, a FormView element named <code>FormViewElement</code> might be rendered on the client-side as <code>ctl00_ContentPlaceHolder1_FormViewElement</code>.</p>

<p>Technically, it&#8217;s not mangling; VS .NET is qualifying the element name to prevent name clashes. Still, it&#8217;s irritating, because client-side Javascript can&#8217;t directly reference these elements, and finding them through some hack involving <code>getElementByID()</code> risks being broken if/when the format for mangling is changed. <a href="http://www.developersdex.com/asp/message.asp?p=1116&amp;ID=%3CeqZicAFzFHA.156%40tk2msftngp13.phx.gbl%3E">This guy</a> ran into this problem, and the responses he got are fairly typical of the advice normally given.</p>

<p>The correct way to do it is to use the <code>ClientID</code> property of the control underlying the element you will be referencing. You can then form the Javascript at compile-time to accurately reference the rendered element.</p>

<p>So, for example, if you&#8217;re working with a FormView defined like this:</p>

<p><code>&lt;asp:FormView ID="FormView1" runat="server" DataSourceID="DataSource"&gt;</code></p>

<p>On the client-side, this is rendered within a table something like this:
<code>&lt;table id="ctl00_ContentPlaceHolder1_FormView1"&gt;</code></p>

<p>To address this element, form and register your Javascript like this:</p>

<pre>
string js = "&lt;script language='javascript'&gt;document.getElementById('" 
          + FormView1.ClientID + "').style.visibility='hidden'&lt;/script&gt;";
Page.RegisterStartupScript("Invisibility", js);
</pre>

<p><em>Update:</em> Bleh, use <code>ClientScriptManager.RegisterStartupScript(...)</code>&#8230;<code>Page.RegisterStartupScript(...)</code> has been deprecated.</p>
]]></content:encoded>
			<wfw:commentRss>http://uzair.nairang.org/articles/2005/10/14/asp-net-2-0-name-mangling/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

