<?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>NetQuarry &#187; Code</title>
	<atom:link href="http://www.netquarry.com/index.php/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.netquarry.com</link>
	<description>The Enterprise Application Platform</description>
	<lastBuildDate>Wed, 21 Apr 2010 18:30:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Chrome 2.0 and Browser Compatibility</title>
		<link>http://www.netquarry.com/index.php/2009/06/chrome-20-and-browser-compatibility-10332/</link>
		<comments>http://www.netquarry.com/index.php/2009/06/chrome-20-and-browser-compatibility-10332/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 19:05:56 +0000</pubDate>
		<dc:creator>Cam Woods</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Platform]]></category>

		<guid isPermaLink="false">http://www.netquarry.com/index.php/2009/06/chrome-20-and-browser-compatibility-10332/</guid>
		<description><![CDATA[Chrome 2.0 renders some tables with empty content.  Here's the fix and why the NetQuarry platform insulates its clients from browser compatibility problems.]]></description>
			<content:encoded><![CDATA[<p>Google Chrome 2.0 was released recently.&#160; We’re big fans of Chrome.&#160; It’s fast, maximizes screen real estate, and, overall, very compatible.&#160; When Chrome 1.0 rolled out we found very few incompatibilities with it.&#160; Our platform, and applications developed on our platform, looked great on Chrome 1.0 with few or no changes.</p>
<p>Unfortunately <strong>Chrome 2.0 rolled out with some significant rendering problems.</strong>&#160; Actually it looks to us like it might be just one problem, but with wide-ranging repercussions.&#160; Essentially a lot of pages get rendered with a lot of missing content – blank tables!&#160; For the NetQuarry platform the result was that our Datasheet (a very functional bound data grid) was rendered in Chrome 2.0 as an empty grid.&#160; A few icon buttons rendered, but the text content was gone!&#160; One day we were on Chrome 1.x and everything was fine, and the next day Chrome 2.0 was pushed out to us (like it or not) and voila! </p>
<p>After quickly verifying that it was a Chrome 2.0-specific problem, we did some Googling.&#160; We expected to find lots of people complaining about this and some quick help on a fix or workaround.&#160; Surprisingly there didn’t seem to be a widespread uproar.&#160; We did find that it was a known problem and that lots of main stream sites were essentially unusable with Chrome 2.0 (<a href="http://code.google.com/p/chromium/issues/detail?id=9904">http://code.google.com/p/chromium/issues/detail?id=9904</a>).&#160; Apparently the list of affected sites includes Facebook, Twitter, WordPress, and even Google Calendar. Unfortunately my search turned up no tips on what to do about it.&#160; It seemed to be some kind of clipping problem that was found before Chrome 2.0 was pushed out to general distribution, but not fixed until after that (or in subsequent releases so far).&#160; Seeing that the problem was so widespread we decided to wait a few days assuming that Google would push out a fix.&#160; A few days later Chrome v2.0.172.31 was pushed out, but lo and behold, the problem persisted.</p>
<p>After a few more days, and customer complaints, we decided that we couldn’t wait.&#160; We did some testing on our datasheet and more Googling and found this Chrome issue (<a href="http://code.google.com/p/chromium/issues/detail?id=13333">http://code.google.com/p/chromium/issues/detail?id=13333</a>) which matched our problem exactly.&#160; What’s more it gave us a suitable workaround.&#160; Five minutes later we had the fix in test and shortly after that it was checked in and ready for the next build.&#160; Here’s our thanks to <a href="http://code.google.com/u/terrybarthdesign/">terrybarthdesign</a> for providing the workaround.&#160; In short, <strong>Chrome 2.0 does not like the overflow:hidden style on a tr tag</strong>.&#160; With the overflow hidden the entire table row content is not rendered.&#160; The content is there in the HTML and sometimes flashes briefly when the page is first rendered, but it doesn’t render.</p>
<p>The frustrating thing about this was that it was actually pretty hard to find this.&#160; We tried Googling on things like “empty table Chrome 2.0”, “missing data Chrome”, “blank grid Chrome”, and about every combination of similar keywords that we could think of and it wasn’t until late last night that we stumbled upon the issue report from <a href="http://code.google.com/u/terrybarthdesign/">terrybarthdesign</a>.</p>
<p>There are really two purposes for this post.&#160; The first is to hopefully help someone else stumble onto a way to resolve a very significant problem.&#160; The second, is to point out that the great thing about a platform like NetQuarry is that we, NetQuarry, spent our time figuring this out – once.&#160; Our clients don’t have to worry about it.&#160; Well, they had to worry about it until we fixed it of course, but we investigated and determined it was a Chrome bug, we explained what was going on, we experimented, tested, researched, and provided a fix in our platform – and all our clients benefited.&#160; Today or tomorrow we’ll be releasing a new version of the platform (which was coming regardless) and it will have this fix.&#160; Our clients won’t have to do a thing except install the new platform.&#160; They won’t have to change their code one iota.</p>
<p><strong>The NetQuarry platform supports all recent versions of Chrome, Firefox, Safari, Opera, and IE 6, 7, and 8.</strong>&#160; The platform takes care of all the browser differences with no overhead for our clients.&#160; And, when a supported browser releases a new version, NetQuarry makes sure that the platform is completely compatible.&#160; Better yet, the platform is engineered to ensure that such breakage rarely occurs.&#160; The platform is designed not just for compatibility with the latest version of each browser, but for forward compatibility as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.netquarry.com/index.php/2009/06/chrome-20-and-browser-compatibility-10332/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Master Pages, AJAX, and Javascript</title>
		<link>http://www.netquarry.com/index.php/2009/03/master-pages-ajax-and-javascript-10292/</link>
		<comments>http://www.netquarry.com/index.php/2009/03/master-pages-ajax-and-javascript-10292/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 00:19:48 +0000</pubDate>
		<dc:creator>Cam Woods</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Platform]]></category>

		<guid isPermaLink="false">http://www.netquarry.com/index.php/2009/03/master-pages-ajax-and-javascript-2-10292/</guid>
		<description><![CDATA[We recently decided to add support for MasterPages to the NetQuarry Enterprise Application Platform. The platform provides a set of .aspx “templates” that are used to host content in various configurations. The standard templates include Wizard, Console, and several flavors of Subform templates as well as support for custom templates. The basic idea is to [...]]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal"><span class="articletitle1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #333333; font-size: 10pt; font-weight: normal; mso-bidi-font-weight: bold">We recently decided to add support for MasterPages to the NetQuarry Enterprise Application Platform.<span style="mso-spacerun: yes"> </span>The platform provides a set of .aspx “templates” that are used to host content in various configurations.<span style="mso-spacerun: yes"> </span>The standard templates include Wizard, Console, and several flavors of Subform templates as well as support for custom templates.<span style="mso-spacerun: yes"> </span>The basic idea is to support hosting templates in .master pages.<span style="mso-spacerun: yes"> </span>Note that NetQuarry is currently using .Net 2.0. </span> </span></p>
<p class="MsoNormal"><span class="articletitle1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #333333; font-size: 10pt; font-weight: normal; mso-bidi-font-weight: bold">Everything started out well enough.<span style="mso-spacerun: yes"> </span>I created a master page called minimal.master and added it to my project.<span style="mso-spacerun: yes"> </span>The .master file was very simple:</span></span><span class="articletitle1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #333333; font-size: 10pt; font-weight: normal; mso-bidi-font-weight: bold"> </span> </span></p>
<p class="Code"><span style="background: yellow; mso-highlight: yellow">&lt;%</span>@ <span style="color: #a31515">Master</span> <span style="color: red">Language</span>=&#8221;C#&#8221; <span style="color: red">AutoEventWireup</span>=&#8221;true&#8221; <span style="color: red">CodeBehind</span>=&#8221;minimal.master.cs&#8221; <span style="color: red">Inherits</span>=&#8221;NetQuarry.minimal&#8221; <span style="background: yellow; mso-highlight: yellow">%&gt; </span></p>
<p class="Code"><span style="background: yellow; mso-highlight: yellow">&lt;%</span>@ <span style="color: #a31515">Register</span> <span style="color: red">TagPrefix</span>=&#8221;eap&#8221; <span style="color: red">Namespace</span>=&#8221;NetQuarry.WebControls&#8221; <span style="color: red">Assembly</span>=&#8221;EAP.WebControls&#8221; <span style="background: yellow; mso-highlight: yellow">%&gt; </span></p>
<p class="Code">&lt;!<span style="color: #a31515">DOCTYPE</span> <span style="color: red">HTML</span> <span style="color: red">PUBLIC</span> &#8220;-//W3C//DTD HTML 4.0 Transitional//EN&#8221; &gt;</p>
<p class="Code">&lt;<span style="color: #a31515">html</span> <span style="color: red">xmlns</span>=&#8221;http://www.w3.org/1999/xhtml&#8221; &gt;<br />
&lt;<span style="color: #a31515">head</span> <span style="color: red">runat</span>=&#8221;server&#8221;&gt;<br />
<span style="mso-tab-count: 1"> </span>&lt;<span style="color: #a31515">title</span> <span style="color: red">runat</span>=&#8221;server&#8221; <span style="color: red">id</span>=&#8221;pageTitle&#8221;&gt;Untitled Page&lt;/<span style="color: #a31515">title</span>&gt;<br />
<span style="mso-spacerun: yes"> </span>&lt;<span style="color: #a31515">asp</span>:<span style="color: #a31515">ContentPlaceHolder</span> <span style="color: red">id</span>=&#8221;header&#8221; <span style="color: red">runat</span>=&#8221;server&#8221;&gt;<br />
<span style="mso-spacerun: yes"> </span>&lt;/<span style="color: #a31515">asp</span>:<span style="color: #a31515">ContentPlaceHolder</span>&gt;<br />
&lt;/<span style="color: #a31515">head</span>&gt;</p>
<p class="Code">&lt;<span style="color: #a31515">body</span> <span style="color: red">runat</span>=&#8221;server&#8221; <span style="color: red">id</span>=&#8221;body&#8221; <span style="color: red">class</span>=&#8221;background&#8221;&gt;<br />
<span style="mso-tab-count: 1"> </span>&lt;<span style="color: #a31515">esp</span>:<span style="color: #a31515">ContentPlaceHolder</span> <span style="color: red">id</span>=&#8221;content&#8221; <span style="color: red">runat</span>=&#8221;server&#8221;/&gt;<br />
&lt;/<span style="color: #a31515">body</span>&gt;<br />
&lt;/<span style="color: #a31515">html</span>&gt;</p>
<p class="MsoNormal"><span class="articletitle1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #333333; font-size: 10pt; font-weight: normal; mso-bidi-font-weight: bold">I made a few quick modifications to my templates wrapping my original header and body contents in appropriate asp:Content controls:</span></span><span class="articletitle1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #333333; font-size: 10pt; font-weight: normal; mso-bidi-font-weight: bold"> </span> </span></p>
<p class="Code">&lt;<span style="color: #a31515">asp</span>:<span style="color: #a31515">Content</span> <span style="color: red">ID</span>=&#8221;header&#8221; <span style="color: red">ContentPlaceHolderID</span>=&#8221;header&#8221; <span style="color: red">runat</span>=&#8221;Server&#8221;&gt;<br />
&lt;/<span style="color: #a31515">asp</span>:<span style="color: #a31515">Content</span>&gt;</p>
<p class="Code">&lt;<span style="color: #a31515">asp</span>:<span style="color: #a31515">Content</span> <span style="color: red">ID</span>=&#8221;content&#8221; <span style="color: red">ContentPlaceHolderID</span>=&#8221;content&#8221; <span style="color: red">runat</span>=&#8221;Server&#8221;&gt;<br />
&lt;/<span style="color: #a31515">asp</span>:<span style="color: #a31515">Content</span>&gt;</p>
<p class="MsoNormal"><span class="articletitle1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #333333; font-size: 10pt; font-weight: normal; mso-bidi-font-weight: bold">A bit more tweaking, the basics were there, but I still had problems.<span style="mso-spacerun: yes"> </span>The big problem was that the NetQuarry platform is used to create web applications, not web sites.<span style="mso-spacerun: yes"> </span>Our applications include a fair amount of javascript and  AJAX and using master pages had broken lots of script.<span style="mso-spacerun: yes"> </span>It didn’t take long for me to figure out that the main problem was that all my client-side elements now had mangled names.<span style="mso-spacerun: yes"> </span>For example, instead of a textbox being named something like “first_name”, it was being rendered into the HTML as “ctl00_content_first_name”.<span style="mso-spacerun: yes"> </span>This mangling broke our script, and badly. </span> </span></p>
<p class="MsoNormal"><span class="articletitle1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #333333; font-size: 10pt; font-weight: normal; mso-bidi-font-weight: bold">The cause of the mangling is the .Net NamingContainer idea.<span style="mso-spacerun: yes"> </span>NamingContainers allow a page to host multiple instances of an object by automatically generating unique client-side names that represent the control hierarchy on the server.<span style="mso-spacerun: yes"> </span>In this case, the MasterPage class itself was a NamingContainer as well as the ContentPlaceHolder control.<span style="mso-spacerun: yes"> </span>Since I hadn’t provided an ID for my MasterPage .Net named it ctl00.<span style="mso-spacerun: yes"> </span>I had named the ContentPlaceHolder for the main page content “content”.<span style="mso-spacerun: yes"> </span>So, since my existing page content was all contained in the “content” ContentPlaceHolder and it was in turn contained in the “ctl00” MasterPage, .Net composed a unique client-side name for the any control in the “content”<span style="mso-spacerun: yes"> </span>prefixed with “ctl00_content_” and, voila, broken script. </span> </span></p>
<p class="MsoNormal"><span class="articletitle1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #333333; font-size: 10pt; font-weight: normal; mso-bidi-font-weight: bold">Now NamingContainers are a great feature of .Net and they allow a lot of things to work seamlessly.<span style="mso-spacerun: yes"> </span>However, in this case I didn’t want any stinking NamingContainers.<span style="mso-spacerun: yes"> </span>Unfortunately, there’s no way to turn off the NamingContainer feature of any control marked as a NamingContainer (a control is marked as a NamingContainer by deriving from the INamingContainer marker interface).<span style="mso-spacerun: yes"> </span><span style="mso-spacerun: yes"> </span>Hint to Microsoft, this would be a good feature. </span> </span></p>
<p class="MsoNormal"><span class="articletitle1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: #333333; font-size: 10pt; font-weight: normal; mso-bidi-font-weight: bold">I actually spent about two days fighting with this and scouring the internet to see if anyone else had come up with a solution.<span style="mso-spacerun: yes"> </span>I did find several partial solutions that helped me move in the right direction.<span style="mso-spacerun: yes"> </span>First there was a good article about MasterPages in general on <a href="http://www.odetocode.com/"><span style="mso-bidi-font-weight: normal">www.OdeToCode.com</span></a> –</span></span><span class="articletitle1"><span style="color: #333333; font-size: 13pt"> </span></span><a href="http://www.odetocode.com/articles/450.aspx">ASP.Net 2.0 &#8211; Master Pages: Tips, Tricks, and Traps</a>.<span style="mso-spacerun: yes"> </span>A bit more digging and I found a partial solution on Rick Strahl’s Web Log – <a href="http://www.west-wind.com/WebLog/posts/4605.aspx">Overriding ClientID and UniqueID on ASP.NET controls</a>.<span style="mso-spacerun: yes"> </span>I’ve found Rick’s blog to be very helpful in the past.<span style="mso-spacerun: yes"> </span>And, that article pointed me to one other helpful blog on glJakal blog – <a href="http://www.gljakal.com/blog/2007/09/12/getting-rid-of-the-naming-container-in-aspnet-20/">Getting rid of the Naming Container in asp.net 2.0</a>.</p>
<p class="MsoNormal">Together these articles showed how to defeat the NamingContainer for client-side naming.<span style="mso-spacerun: yes"> </span>The full code of the final solution is below, but defeating the NamingContainer for client-side id mangling involved overriding the ClientID, UniqueID, and ID properties on the MasterPage and ContentPlaceHolder classes to return null, and the NamingContainer property on the ContentPlaceHolder class to return null.<span style="mso-spacerun: yes"> </span>With that my pages rendered well and my javascript worked!</p>
<p class="MsoNormal">Alas, what didn’t work was any postbacks.<span style="mso-spacerun: yes"> </span>The problem was that the id’s of the client-side controls no longer matched the control hierarchy on the server!<span style="mso-spacerun: yes"> </span>It didn’t take me long to figure out that what I needed to do was figure out a way to make the server-side control hierarchy match my client-side naming.<span style="mso-spacerun: yes"> </span>Essentially this meant making the server-side hierarchy look like my pre-MasterPage hierarchy, as far as NamingContainers go that is.<span style="mso-spacerun: yes"> </span></p>
<p class="MsoNormal">After a day of failed attempts, I was able to work out how to accomplish this.<span style="mso-spacerun: yes"> </span>The secret was to rearrange the control tree during the page PreInit event.<span style="mso-spacerun: yes"> </span>The PreInit event is available only to Page objects and is the only time that you can rearrange controls in the way I needed to.<span style="mso-spacerun: yes"> </span>Eventually I figured out that two things needed to be done: 1) move the controls out of the MasterPage and ContentPlaceHolder controls so that .Net can match up the server-side controls with the unmangled client-side id’s, and 2) leave the controls in the MasterPage and ContentPlaceHolder controls for rendering purposes so that the contents are rendered correctly with respect to other elements in the MasterPage.</p>
<p class="MsoNormal"><strong>May 20, 2009 update:</strong> Thanks to Ritchie Annand for discovering a problem in the original code when run with .Net tracing enabled (via the &lt;trace&gt; tag) and pointing the way to a fix.  The code now includes a fix to ensure that all hosted controls get an ID which is required when tracing (see the call to AssignIDs() in TemplateMaster::OnPreRender()).  Note that there is still a glitch that affects our platform under certain circumstances when .Net tracing is enabled and <em>pageOutput </em>is turned on.</p>
<p class="MsoNormal">To use the code below you need to do just a few things:</p>
<ul style="margin-top: 0in" type="disc">
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list .5in">Include the code below in your project,</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list .5in">Derive your master page from TemplateMaster instead of MasterPage,</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list .5in">Use the &lt;eap:ContentPlaceHolder&gt; tag in place of &lt;asp:ContentPlaceHolder&gt;,</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list .5in">In your master page .designer file, use the new ContentPlaceHolder instead of the .Net ContentPlaceHolder, and</li>
<li class="MsoNormal" style="mso-list: l0 level1 lfo1; tab-stops: list .5in">In your page’s PreInit event, call the TemplateMaster.Rehost() method, something like this:<span style="mso-spacerun: yes"> </span></li>
</ul>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnPreInit(EventArgs e)
{
    <span class="rem">//--- Rehost controls from MasterPage/Content/ContentPlaceHolder hierarchy onto the </span>
    <span class="rem">//--- Page itself.  This has the effect of cancelling the NamingContainer effect of </span>
    <span class="rem">//--- these controls on the server. </span>

    <span class="kwrd">if</span> (<span class="kwrd">this</span>.Master <span class="kwrd">is</span> TemplateMaster)
    {
        (<span class="kwrd">this</span>.Master <span class="kwrd">as</span> TemplateMaster).Rehost();
    } 

    <span class="kwrd">base</span>.OnPreInit(e);
}</pre>
<p class="MsoNormal">And finally, here’s the code:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode"><span class="rem">//---------------------------------------------------------------------------------------</span>
<span class="rem">// Copyright (c) 2005-2009 by NetQuarry, Inc.</span>
<span class="rem">// All rights reserved.</span>
<span class="rem">//</span>
<span class="rem">// Licensed under the Eiffel Forum License, version 2:</span>
<span class="rem">//</span>
<span class="rem">// 1. Permission is hereby granted to use, copy, modify and/or</span>
<span class="rem">// distribute this package, provided that:</span>
<span class="rem">// * copyright notices are retained unchanged,</span>
<span class="rem">// * any distribution of this package, whether modified or not,</span>
<span class="rem">// includes this license text.</span>
<span class="rem">// 2. Permission is hereby also granted to distribute binary programs</span>
<span class="rem">// which depend on this package. If the binary program depends on a</span>
<span class="rem">// modified version of this package, you are encouraged to publicly</span>
<span class="rem">// release the modified version of this package.</span>
<span class="rem">//</span>
<span class="rem">// THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT WARRANTY. ANY EXPRESS OR</span>
<span class="rem">// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED</span>
<span class="rem">// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE</span>
<span class="rem">// DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE TO ANY PARTY FOR ANY</span>
<span class="rem">// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL</span>
<span class="rem">// DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THIS PACKAGE.</span>
<span class="rem">//</span>
<span class="rem">// www.netquarry.com</span>
<span class="rem">//---------------------------------------------------------------------------------------</span>

<span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Web;
<span class="kwrd">using</span> System.Web.UI;
<span class="kwrd">using</span> System.Web.UI.WebControls;
<span class="kwrd">using</span> System.Web.UI.HtmlControls;
<span class="kwrd">using</span> System.Text;
<span class="kwrd">using</span> System.Collections.Generic;

[assembly: TagPrefix(<span class="str">"NetQuarry.WebControls"</span>, <span class="str">"eap"</span>)]

<span class="kwrd">namespace</span> NetQuarry.WebControls
{
    <span class="rem">/// &lt;summary&gt; </span>
    <span class="rem">/// Base class that must be used for any master page hosting platform templates. </span>
    <span class="rem">/// &lt;/summary&gt; </span>
    <span class="kwrd">public</span> <span class="kwrd">abstract</span> <span class="kwrd">class</span> TemplateMaster : System.Web.UI.MasterPage
    {
        <span class="kwrd">private</span> <span class="kwrd">class</span> ContentContainer : Control
        {
            <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Render(HtmlTextWriter writer)
            {
                <span class="rem">//base.Render(writer);  // Ignore the normal render. </span>
            }

            <span class="kwrd">public</span> <span class="kwrd">void</span> ExternalRender(HtmlTextWriter writer)
            {
                <span class="kwrd">base</span>.Render(writer);    <span class="rem">// Now render! </span>
            }

            <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnPreRender(EventArgs e)
            {
                <span class="kwrd">base</span>.OnPreRender(e);

                <span class="kwrd">int</span> nIDIndex = 0;

                AssignIDs(<span class="kwrd">this</span>, <span class="kwrd">this</span>.ID, <span class="kwrd">ref</span> nIDIndex);
            }

            <span class="rem">/// &lt;summary&gt;</span>
            <span class="rem">/// In .Net TRACE enabled every control in the hierarchy MUST have and ID and our juggling rehosting </span>
            <span class="rem">/// controls messes up .Net's id assignment.  Here we recursively search through the specified control</span>
            <span class="rem">/// and provide unique ID's to any controls so lacking.</span>
            <span class="rem">/// &lt;/summary&gt;</span>
            <span class="rem">/// &lt;param name="ctrl"&gt;The control whose hierarchy should be scanned and assigned.&lt;/param&gt;</span>
            <span class="rem">/// &lt;param name="baseName"&gt;The base name for any subcontrols.&lt;/param&gt;</span>
            <span class="rem">/// &lt;param name="idIndex"&gt;The ID index to use when assigning a unique ID.&lt;/param&gt;</span>
            <span class="kwrd">private</span> <span class="kwrd">void</span> AssignIDs(Control ctrl, <span class="kwrd">string</span> baseName, <span class="kwrd">ref</span> <span class="kwrd">int</span> idIndex)
            {
                <span class="kwrd">if</span> (<span class="kwrd">string</span>.IsNullOrEmpty(ctrl.ID))
                {
                    ctrl.ID = baseName + idIndex.ToString().PadLeft(3, <span class="str">'0'</span>);
                    idIndex++;
                }

                <span class="kwrd">if</span> (ctrl.Controls != <span class="kwrd">null</span>)
                {
                    <span class="kwrd">foreach</span> (Control child <span class="kwrd">in</span> ctrl.Controls)
                    {
                        AssignIDs(child, baseName, <span class="kwrd">ref</span> idIndex);
                    }
                }
            }
        }

        <span class="kwrd">private</span> <span class="kwrd">class</span> ContentRenderer : Control
        {
            ContentContainer _container = <span class="kwrd">null</span>;

            <span class="kwrd">public</span> ContentRenderer(ContentContainer container)
            {
                _container = container;
            }

            <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Render(HtmlTextWriter writer)
            {
                <span class="kwrd">if</span> (_container != <span class="kwrd">null</span>) _container.ExternalRender(writer); <span class="rem">// Ask associated container to render. </span>
            }
        }

        <span class="rem">/// &lt;summary&gt; </span>
        <span class="rem">/// Defeat the effect of the .Net MasterPage being a NamingContainer with regard </span>
        <span class="rem">/// to client-side NAME and ID attributes rendering by always returning a null ClientID. </span>
        <span class="rem">/// &lt;/summary&gt; </span>
        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> ClientID
        {
            get { <span class="kwrd">return</span> <span class="kwrd">null</span>; }
        }

        <span class="rem">/// &lt;summary&gt; </span>
        <span class="rem">/// Defeat the effect of the .Net MasterPage being a NamingContainer with regard </span>
        <span class="rem">/// to client-side NAME and ID attributes rendering by always returning a null UniqueID. </span>
        <span class="rem">/// &lt;/summary&gt; </span>
        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> UniqueID
        {
            get { <span class="kwrd">return</span> <span class="kwrd">null</span>; }
        }

        <span class="rem">/// &lt;summary&gt; </span>
        <span class="rem">/// Defeat the effect of the .Net MasterPage being a NamingContainer with regard </span>
        <span class="rem">/// to client-side NAME and ID attributes rendering by always returning a null ID. </span>
        <span class="rem">/// &lt;/summary&gt; </span>
        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> ID
        {
            get { <span class="kwrd">return</span> <span class="kwrd">null</span>; }
            set { <span class="kwrd">base</span>.ID = <span class="kwrd">value</span>; }
        }

        <span class="rem">/// &lt;summary&gt; </span>
        <span class="rem">/// Rehost controls from MasterPage/Content/ContentPlaceHolder hierarchy onto the </span>
        <span class="rem">/// Page itself.  This has the effect of cancelling the NamingContainer effect of </span>
        <span class="rem">/// these controls on the server.  </span>
        <span class="rem">/// &lt;/summary&gt; </span>
        <span class="rem">/// &lt;param name="parent"&gt;The parent control whose children should be rehosted.&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name="idIndex"&gt;The ID index to use when providing ID's to controls so lacking.&lt;/param&gt;</span>
        <span class="kwrd">private</span> <span class="kwrd">void</span> MoveControlsToPage(Control parent, <span class="kwrd">ref</span> <span class="kwrd">int</span> idIndex)
        {
            <span class="kwrd">if</span> (<span class="kwrd">base</span>.Page != <span class="kwrd">null</span> &amp;&amp; <span class="kwrd">this</span>.Controls.Count &gt; 0)
            {
                List&lt;Control&gt; lst = <span class="kwrd">new</span> List&lt;Control&gt;(<span class="kwrd">this</span>.Controls.Count);
                ContentContainer container = <span class="kwrd">new</span> ContentContainer();                <span class="rem">// Container will host the controls w/out a NamingContainer. </span>
                ContentRenderer renderer = <span class="kwrd">new</span> ContentRenderer(container);        <span class="rem">// Renderer will render contents of container. </span>

                <span class="rem">//--- In .Net TRACE enabled every control in the hierarchy MUST have</span>
                <span class="rem">//--- and ID and our juggling rehosting controls messes up .Net's id assignment.</span>

                container.ID = <span class="str">"ctlcont"</span> + idIndex.ToString().PadLeft(3, <span class="str">'0'</span>);
                renderer.ID = <span class="str">"ctlrend"</span> + idIndex.ToString().PadLeft(3, <span class="str">'0'</span>);
                idIndex++;

                <span class="rem">//--— Create collection of all controls to move.</span>

                <span class="kwrd">for</span> (<span class="kwrd">int</span> ii = 0; ii &lt; parent.Controls.Count; ii++)
                {
                    lst.Add(parent.Controls[ii]);
                }

                <span class="rem">//--— Determine index of this container. </span>

                Control root = parent;

                <span class="kwrd">while</span> (root != <span class="kwrd">null</span> &amp;&amp; root.Parent != <span class="kwrd">null</span> &amp;&amp; !(root.Parent <span class="kwrd">is</span> Page))
                {
                    root = root.Parent;
                }

                <span class="kwrd">int</span> nIndex = (root == <span class="kwrd">null</span>) ? -1 : root.Parent.Controls.IndexOf(root);

                <span class="rem">//--— Remove controls from original parent and add them to new container. </span>

                <span class="kwrd">for</span> (<span class="kwrd">int</span> ii = 0; ii &lt; lst.Count; ii++)
                {
                    Control ctrl = lst[ii];

                    parent.Controls.Remove(ctrl);
                    container.Controls.AddAt(ii, ctrl);
                }

                <span class="rem">//--— Add new renderer to replace original controls and new container to the page itself. </span>
                <span class="rem">//—-- The container is used to extablish the control hierarchy and in this way collapsing  </span>
                <span class="rem">//—-- the MasterPage so that it doesn’t act as a NamingContainer for the purposes of the </span>
                <span class="rem">//—-- control hierarchy.  The container will ignore the control’s normal Render() method. </span>
                <span class="rem">//--— The renderer has no controls, just a reference to the container.  When the renderer’s </span>
                <span class="rem">//--— Render() method is called it will have the container render in its place.</span>

                parent.Controls.Add(renderer);                    <span class="rem">// Render controls as if contained in master. </span>
                Page.Controls.AddAt(nIndex + 1, container);        <span class="rem">// But host them flat on the page instead of nested in NamingContainers. </span>
            }
        }

        <span class="rem">/// &lt;summary&gt; </span>
        <span class="rem">/// Rehost controls from MasterPage/Content/ContentPlaceHolder hierarchy onto the </span>
        <span class="rem">/// Page itself.  This has the effect of cancelling the NamingContainer effect of </span>
        <span class="rem">/// these controls on the server.  </span>
        <span class="rem">/// &lt;/summary&gt; </span>
        <span class="rem">/// &lt;param name="parent"&gt;The tree of controls from which to rehost.&lt;/param&gt;</span>
        <span class="rem">/// &lt;param name="idIndex"&gt;The ID index to use when providing ID's to controls so lacking.&lt;/param&gt;</span>
        <span class="kwrd">private</span> <span class="kwrd">void</span> RehostMasterControls(Control parent, <span class="kwrd">ref</span> <span class="kwrd">int</span> idIndex)
        {
            <span class="rem">//--— Find all ContentPlaceHolder controls and rehost the children to the page itself. </span>

            <span class="kwrd">foreach</span> (Control ctrl <span class="kwrd">in</span> parent.Controls)
            {
                <span class="kwrd">if</span> (ctrl <span class="kwrd">is</span> NetQuarry.WebControls.ContentPlaceHolder)
                {
                    MoveControlsToPage(ctrl, <span class="kwrd">ref</span> idIndex);        <span class="rem">// Rehost children to page. </span>
                }
                <span class="kwrd">else</span>
                {
                    RehostMasterControls(ctrl, <span class="kwrd">ref</span> idIndex);    <span class="rem">// Recurse. </span>
                }
            }
        }

        <span class="rem">/// &lt;summary&gt;</span>
        <span class="rem">/// Rehost controls from MasterPage/Content/ContentPlaceHolder hierarchy onto the</span>
        <span class="rem">/// Page itself.  This has the effect of cancelling the NamingContainer effect of</span>
        <span class="rem">/// these controls on the server. </span>
        <span class="rem">/// &lt;/summary&gt;</span>
        <span class="kwrd">public</span> <span class="kwrd">void</span> Rehost()
        {
            <span class="kwrd">int</span> nIDIndex = 0;        <span class="rem">// Need to provide unique ID's for controls so lacking.</span>

            RehostMasterControls(<span class="kwrd">this</span>.Page.Master, <span class="kwrd">ref</span> nIDIndex);
        }
    }

    <span class="rem">/// &lt;summary&gt; </span>
    <span class="rem">/// Replacement control for System.Web.UI.WebControls.ContentPlaceHolder for use when it is desired </span>
    <span class="rem">/// to NOT have the MasterPage, Content, and ContentPlaceHolder controls behave as naming </span>
    <span class="rem">/// containers.  There are two aspects to this: 1) the effect a NamingContainer has on the  </span>
    <span class="rem">/// client-side control NAME and ID mangling, and 2) the control hierarchy on the server. </span>
    <span class="rem">/// &lt;/summary&gt; </span>
    <span class="kwrd">public</span> <span class="kwrd">class</span> ContentPlaceHolder : System.Web.UI.WebControls.ContentPlaceHolder
    {
        <span class="rem">/// &lt;summary&gt; </span>
        <span class="rem">/// Defeat the effect of the .Net ContentPlaceHolder being a NamingContainer with regard </span>
        <span class="rem">/// to client-side NAME and ID attributes rendering by always returning a null NamingContainer. </span>
        <span class="rem">/// &lt;/summary&gt; </span>
        <span class="kwrd">public</span> <span class="kwrd">override</span> Control NamingContainer
        {
            get { <span class="kwrd">return</span> <span class="kwrd">null</span>; }
        }

        <span class="rem">/// &lt;summary&gt; </span>
        <span class="rem">/// Defeat the effect of the .Net ContentPlaceHolder being a NamingContainer with regard </span>
        <span class="rem">/// to client-side NAME and ID attributes rendering by always returning a null ClientID. </span>
        <span class="rem">/// &lt;/summary&gt; </span>
        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> ClientID
        {
            get { <span class="kwrd">return</span> <span class="kwrd">null</span>; }
        }

        <span class="rem">/// &lt;summary&gt; </span>
        <span class="rem">/// Defeat the effect of the .Net ContentPlaceHolder being a NamingContainer with regard </span>
        <span class="rem">/// to client-side NAME and ID attributes rendering by always returning a null UniqueID. </span>
        <span class="rem">/// &lt;/summary&gt; </span>
        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> UniqueID
        {
            get { <span class="kwrd">return</span> <span class="kwrd">null</span>; }
        }

        <span class="rem">/// &lt;summary&gt; </span>
        <span class="rem">/// Defeat the effect of the .Net ContentPlaceHolder being a NamingContainer with regard </span>
        <span class="rem">/// to client-side NAME and ID attributes rendering by always returning a null ID. </span>
        <span class="rem">/// &lt;/summary&gt; </span>
        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> ID
        {
            get { <span class="kwrd">return</span> <span class="kwrd">null</span>; }
            set { <span class="kwrd">base</span>.ID = <span class="kwrd">value</span>; }
        }
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.netquarry.com/index.php/2009/03/master-pages-ajax-and-javascript-10292/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Fresh Beginnings</title>
		<link>http://www.netquarry.com/index.php/2009/02/fresh-beginnings-10267/</link>
		<comments>http://www.netquarry.com/index.php/2009/02/fresh-beginnings-10267/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 19:19:43 +0000</pubDate>
		<dc:creator>Ryan Reid</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Platform]]></category>
		<category><![CDATA[Versions]]></category>

		<guid isPermaLink="false">http://www.netquarry.com/index.php/2009/02/fresh-beginnings-10267/</guid>
		<description><![CDATA[One of the things I hear myself saying nearly all the time sounds something like “if I were starting over&#8230;” If you make a living writing software, building websites, building databases, or writing reports you must have, on a regular basis, one of these moments.
For me, the reason I feel this way is because there [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things I hear myself saying nearly all the time sounds something like “if I were starting over&#8230;” If you make a living writing software, building websites, building databases, or writing reports you must have, on a regular basis, one of these moments.</p>
<p>For me, the reason I feel this way is because there are always parts of an application that aren&#8217;t quite right. I&#8217;d like a chance to make it better.</p>
<p>Since this isn’t always possible we’ve made a huge effort to allow for a way to add and remove <em>parts </em>of your application in a simple, safe, and discoverable way. In fact, this idea of “feature versions” is a first class concept in the Platform.</p>
<p>A feature version allows you to add metadata and code and tag it with a name that won’t be available in your live application unless you enable the version. This works for all important metadata objects – pages, mappers, fields, and extensions. Because it works with extensions you can actually write code, add it to the build, installer, and publish it to your live site without any risk of the code kicking in before the feature is absolutely ready.</p>
<p>Feature versions allow you to make your Great New Feature – the one you got to “start over” on – show up at several levels. The simplest way is by setting the version on an extension – for example, say you’ve built Version 1.0 of a task queue feature and you’ve written an extension for Version 2.0 that does much, much more. In this scenario, you would set the MinVersion value on the ‘task’ version to 1 and the MaxVersion to 1. Then you set the MinVersion for the next extension to 2. </p>
<p>When you set the value of the version to 2 your new extensions automatically kicks in. Simple, safe. You’ve just started over.</p>
<p>If you <em>are </em>lucky enough to be starting a new project then you really, really should take a good look at the NetQuarry Platform <strong>today</strong>. Contrary to the popular thinking of project managers and software architects, custom applications do NOT require custom infrastructure. Really. Spend a few minutes with us – talk to <em>one </em>of our customers. It’ll be short. We promise.</p>
<p>NetQuarry – Start Right.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.netquarry.com/index.php/2009/02/fresh-beginnings-10267/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VisualBasic</title>
		<link>http://www.netquarry.com/index.php/2006/09/visualbasic-1037/</link>
		<comments>http://www.netquarry.com/index.php/2006/09/visualbasic-1037/#comments</comments>
		<pubDate>Thu, 14 Sep 2006 02:20:28 +0000</pubDate>
		<dc:creator>Ryan Reid</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Legacy]]></category>
		<category><![CDATA[Product]]></category>
		<category><![CDATA[Rant]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://www.netquarry.com/?p=37</guid>
		<description><![CDATA[It occurs to me, and not just because we write and sell a .NET product, that a good number of owners of large VB 6.0 applications are about to become a little nervous. As part of a proposal for one of these companies, I was tracking down the support dates and end-of-life statements by Microsoft about VB 6.0. It says, basically, that the Visual Basic runtime (or an updated version) will ship will Windows Vista and will be supported fully for 5 years, and not so fully for 5 more years after that.]]></description>
			<content:encoded><![CDATA[<p>It occurs to me, and not just because we write and sell a .NET product, that a good number of owners of large VB 6.0 applications are about to become a little nervous. As part of a proposal for one of these companies, I was tracking down the support dates and end-of-life statements by Microsoft about VB 6.0. It says, basically, that the Visual Basic runtime (or an updated version) will ship will Windows Vista and will be supported fully for 5 years, and not so fully for 5 more years after that.</p>
<p>The actual support of Visual Basic and Visual Studio 6.0 (in which VB 6.0 shipped) is over now. This sort of surprised me. I assumed that Microsoft would continue to support VB more or less forever, silly as that may sound. The actual dates for &#8220;support&#8221; are here: <a href="http://support.microsoft.com/lifecycle/search/?sort=PNα=Visual+Basic+6.0">Visual Basic Product Lifecycle</a>, and this says that real support ended 3/31/2005, and extended support will last until 4/8/2008.</p>
<p>I was a <em>long</em> time Visual Basic user &#8212; our last product used it as the extension language &#8212; and if I had a large VB 6.0 application, I would probably worry. I&#8217;m pretty sure that many VB 6.0 applications will continue to run. I&#8217;m also pretty sure that if they didn&#8217;t, and if they were mission critical, most enterprises would be able to find someone to tweak their application so that it would continue correctly.</p>
<p>What <em>would</em> worry me is less concrete. If you manage or develop an important product for a large enterprise and the language that the application was written in was out of official support, I&#8217;d start thinking that maybe it was time to think about a port. Why? If nothing else because anything large enough to worry about is likely to take until April of 2008 to get ported.</p>
<p>All of this is a somewhat shameless pitch for NetQuarry, of course. Actually, I don&#8217;t see how one would begin a reasonable port of a large Visual Basic application without at least the start of the infrastructure that we provide. Many of these applications are <strong>huge</strong> &#8212; e.g. 1000s of pages, tables, and complex rules. Most of the folks who built and probably deeply understand the application are off on other projects (presumably in a more modern language).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.netquarry.com/index.php/2006/09/visualbasic-1037/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
