<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Random Blahgging</title>
    <link>http://blog.jasonbunting.com/</link>
    <description />
    <language>en-us</language>
    <copyright>Jason Bunting</copyright>
    <lastBuildDate>Mon, 04 May 2009 23:22:50 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>jason@jasonbunting.com</managingEditor>
    <webMaster>jason@jasonbunting.com</webMaster>
    <item>
      <trackback:ping>http://blog.jasonbunting.com/Trackback.aspx?guid=d578f8c3-e975-4fca-8100-404db4de8af2</trackback:ping>
      <pingback:server>http://blog.jasonbunting.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.jasonbunting.com/PermaLink,guid,d578f8c3-e975-4fca-8100-404db4de8af2.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://blog.jasonbunting.com/CommentView,guid,d578f8c3-e975-4fca-8100-404db4de8af2.aspx</wfw:comment>
      <wfw:commentRss>http://blog.jasonbunting.com/SyndicationService.asmx/GetEntryCommentsRss?guid=d578f8c3-e975-4fca-8100-404db4de8af2</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A few mornings ago I went into work, and per my usual routine, opened Outlook, opened
IE 7 (we are developing an app that has to run against that sorry excuse for a browser),
open Visual Studio, etc. 
</p>
        <p>
Once my laptop decided it was done with these seemingly simple tasks, I gave focus
to VS, went to the File menu, down to Recent Projects and selected that VS solution
which is the current source of my income. As soon as the previously-opened files were
displayed, Visual Studio simply shutdown - rather quickly, too. There were no messages,
warnings, requests for sending an error report to headquarters, etc. it simply shutdown.
</p>
        <p>
Hmm, okay.
</p>
        <p>
So, I tried it again and the same thing happens. So, I did something I rarely do,
and rebooted Windows (XP Pro, of course), hoping that would "fix" the problem. Nope,
no dice. Meanwhile, a coworker needed some help with something, so I go to his desk
and in the process of that discussion, I mention <a title="PowerCommands for Visual Studio 2008" href="http://code.msdn.microsoft.com/PowerCommands" target="_blank">PowerCommands
for Visual Studio 2008</a> to him and he installs it because he really liked my description
of the "Collapse Projects" feature, as we have quite a large number of projects in
this solution (more than I think we should have, but <em>whatever</em>) and after
a few of them are open, solution explorer becomes a bit unwieldy and useless.
</p>
        <p>
No sooner than he installs PowerCommands and starts Visual Studio back up does it
close up exactly as it had been doing for me. How serendipituous! Because I had been
running PowerCommands for a week or two with no problems though, I was reluctant to
think it was the cause of the problem; yet I couldn't deny what my eyes had just seen. 
</p>
        <p>
So, I searched around and after seeing this as being a problem for quite a few people,
a lot of whom use XAML for WPF, and their various attempts at fixing the problem (my
least favorite being to simply uninstall PowerCommands and cease using it), decided
to try <a href="http://stackoverflow.com/questions/153942/what-causes-visual-studio-2008-sp1-to-crash-when-switch-to-design-view-of-a-wpf-a/463719#463719" target="_blank">the
following, which I found on Stack Overflow</a> and has worked for all 3 of the people
on my team which have had the problem - here is the solution:
</p>
        <p>
You are going to modify the <strong>devenv.exe.config</strong> file, which can be
found, <em>typically</em>, in this folder location:
</p>
        <blockquote>
          <p>
            <strong>32-bit Windows</strong>
            <br />
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE
</p>
          <p>
            <strong>64-bit Windows</strong>
            <br />
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE
</p>
        </blockquote>
        <p>
Open the file in Notepad or some other suitable text editor, and add the following
(assemblyBinding node shown for context):
</p>
        <div class="wlWriterEditableSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:98c61672-6d92-423f-a82d-199c415a35d3" style="margin: 0px; padding: 0px; display: inline; float: none; font-size: 1.3em;">
          <pre style="overflow: auto; background-color: rgb(255, 255, 255); white-space: pre-wrap; word-wrap: break-word;">
            <span style="color: rgb(0, 0, 0);">
            </span>
            <span style="color: rgb(0, 0, 255);">&lt;</span>
            <span style="color: rgb(128, 0, 0);">assemblyBinding </span>
            <span style="color: rgb(255, 0, 0);">xmlns</span>
            <span style="color: rgb(0, 0, 255);">="urn:schemas-microsoft-com:asm.v1"</span>
            <span style="color: rgb(0, 0, 255);">&gt;</span>
            <span style="color: rgb(0, 0, 0);"> ... </span>
            <span style="color: rgb(0, 0, 255);">&lt;</span>
            <span style="color: rgb(128, 0, 0);">dependentAssembly</span>
            <span style="color: rgb(0, 0, 255);">&gt;</span>
            <span style="color: rgb(0, 0, 0);">
            </span>
            <span style="color: rgb(0, 0, 255);">&lt;</span>
            <span style="color: rgb(128, 0, 0);">assemblyIdentity </span>
            <span style="color: rgb(255, 0, 0);">name</span>
            <span style="color: rgb(0, 0, 255);">="Microsoft.PowerCommands"</span>
            <span style="color: rgb(255, 0, 0);"> publicKeyToken</span>
            <span style="color: rgb(0, 0, 255);">="null"</span>
            <span style="color: rgb(255, 0, 0);"> culture</span>
            <span style="color: rgb(0, 0, 255);">="neutral"</span>
            <span style="color: rgb(0, 0, 255);">/&gt;</span>
            <span style="color: rgb(0, 0, 0);">
            </span>
            <span style="color: rgb(0, 128, 0);">&lt;!--</span>
            <span style="color: rgb(0, 128, 0);"> For
32-bit systems, uncomment this one &lt;codeBase version="1.1.0.0" href="href="C:\Program
Files\PowerCommands\Microsoft.PowerCommands.dll"/&gt; </span>
            <span style="color: rgb(0, 128, 0);">--&gt;</span>
            <span style="color: rgb(0, 0, 0);">
            </span>
            <span style="color: rgb(0, 128, 0);">&lt;!--</span>
            <span style="color: rgb(0, 128, 0);"> For
64-bit systems, uncomment and use this one &lt;codeBase version="1.1.0.0" href="C:\Program
Files (x86)\PowerCommands\Microsoft.PowerCommands.dll"/&gt; </span>
            <span style="color: rgb(0, 128, 0);">--&gt;</span>
            <span style="color: rgb(0, 0, 0);">
            </span>
            <span style="color: rgb(0, 0, 255);">&lt;/</span>
            <span style="color: rgb(128, 0, 0);">dependentAssembly</span>
            <span style="color: rgb(0, 0, 255);">&gt;</span>
            <span style="color: rgb(0, 0, 0);"> ... </span>
            <span style="color: rgb(0, 0, 255);">&lt;/</span>
            <span style="color: rgb(128, 0, 0);">assemblyBinding</span>
            <span style="color: rgb(0, 0, 255);">&gt;</span>
          </pre>
          <!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com -->
        </div>
        <p>
        </p>
        <p>
Hopefully this helps someone, it's a sneaky bug.
</p>
        <img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=d578f8c3-e975-4fca-8100-404db4de8af2" />
      </body>
      <title>FIX: PowerCommands for Visual Studio 2008 Crashes IDE</title>
      <guid isPermaLink="false">http://blog.jasonbunting.com/PermaLink,guid,d578f8c3-e975-4fca-8100-404db4de8af2.aspx</guid>
      <link>http://blog.jasonbunting.com/2009/05/04/FIX+PowerCommands+For+Visual+Studio+2008+Crashes+IDE.aspx</link>
      <pubDate>Mon, 04 May 2009 23:22:50 GMT</pubDate>
      <description>&lt;p&gt;
A few mornings ago I went into work, and per my usual routine, opened Outlook, opened
IE 7 (we are developing an app that has to run against that sorry excuse for a browser),
open Visual Studio, etc. 
&lt;/p&gt;
&lt;p&gt;
Once my laptop decided it was done with these seemingly simple tasks, I gave focus
to VS, went to the File menu, down to Recent Projects and selected that VS solution
which is the current source of my income. As soon as the previously-opened files were
displayed, Visual Studio simply shutdown - rather quickly, too. There were no messages,
warnings, requests for sending an error report to headquarters, etc. it simply shutdown.
&lt;/p&gt;
&lt;p&gt;
Hmm, okay.
&lt;/p&gt;
&lt;p&gt;
So, I tried it again and the same thing happens. So, I did something I rarely do,
and rebooted Windows (XP Pro, of course), hoping that would "fix" the problem. Nope,
no dice. Meanwhile, a coworker needed some help with something, so I go to his desk
and in the process of that discussion, I mention &lt;a title="PowerCommands for Visual Studio 2008" href="http://code.msdn.microsoft.com/PowerCommands" target="_blank"&gt;PowerCommands
for Visual Studio 2008&lt;/a&gt; to him and he installs it because he really liked my description
of the "Collapse Projects" feature, as we have quite a large number of projects in
this solution (more than I think we should have, but &lt;em&gt;whatever&lt;/em&gt;) and after
a few of them are open, solution explorer becomes a bit unwieldy and useless.
&lt;/p&gt;
&lt;p&gt;
No sooner than he installs PowerCommands and starts Visual Studio back up does it
close up exactly as it had been doing for me. How serendipituous! Because I had been
running PowerCommands for a week or two with no problems though, I was reluctant to
think it was the cause of the problem; yet I couldn't deny what my eyes had just seen. 
&lt;/p&gt;
&lt;p&gt;
So, I searched around and after seeing this as being a problem for quite a few people,
a lot of whom use XAML for WPF, and their various attempts at fixing the problem (my
least favorite being to simply uninstall PowerCommands and cease using it), decided
to try &lt;a href="http://stackoverflow.com/questions/153942/what-causes-visual-studio-2008-sp1-to-crash-when-switch-to-design-view-of-a-wpf-a/463719#463719" target="_blank"&gt;the
following, which I found on Stack Overflow&lt;/a&gt; and has worked for all 3 of the people
on my team which have had the problem - here is the solution:
&lt;/p&gt;
&lt;p&gt;
You are going to modify the &lt;strong&gt;devenv.exe.config&lt;/strong&gt; file, which can be
found, &lt;em&gt;typically&lt;/em&gt;, in this folder location:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;strong&gt;32-bit Windows&lt;/strong&gt;
&lt;br&gt;
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;64-bit Windows&lt;/strong&gt;
&lt;br&gt;
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Open the file in Notepad or some other suitable text editor, and add the following
(assemblyBinding node shown for context):
&lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:98c61672-6d92-423f-a82d-199c415a35d3" style="margin: 0px; padding: 0px; display: inline; float: none; font-size: 1.3em;"&gt;&lt;pre style="overflow: auto; background-color: rgb(255, 255, 255); white-space: pre-wrap; word-wrap: break-word;"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;assemblyBinding &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;xmlns&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="urn:schemas-microsoft-com:asm.v1"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;dependentAssembly&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;assemblyIdentity &lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt;name&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="Microsoft.PowerCommands"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; publicKeyToken&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="null"&lt;/span&gt;&lt;span style="color: rgb(255, 0, 0);"&gt; culture&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;="neutral"&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;/&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;&amp;lt;!--&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt; For
32-bit systems, uncomment this one &amp;lt;codeBase version="1.1.0.0" href="href="C:\Program
Files\PowerCommands\Microsoft.PowerCommands.dll"/&amp;gt; &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;--&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;&amp;lt;!--&lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt; For
64-bit systems, uncomment and use this one &amp;lt;codeBase version="1.1.0.0" href="C:\Program
Files (x86)\PowerCommands\Microsoft.PowerCommands.dll"/&amp;gt; &lt;/span&gt;&lt;span style="color: rgb(0, 128, 0);"&gt;--&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;dependentAssembly&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;span style="color: rgb(0, 0, 0);"&gt; ... &lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: rgb(128, 0, 0);"&gt;assemblyBinding&lt;/span&gt;&lt;span style="color: rgb(0, 0, 255);"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Hopefully this helps someone, it's a sneaky bug.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=d578f8c3-e975-4fca-8100-404db4de8af2" /&gt;</description>
      <comments>http://blog.jasonbunting.com/CommentView,guid,d578f8c3-e975-4fca-8100-404db4de8af2.aspx</comments>
      <category>Software</category>
      <category>Visual Studio</category>
      <category>Work</category>
    </item>
    <item>
      <trackback:ping>http://blog.jasonbunting.com/Trackback.aspx?guid=43b40452-8331-4160-a966-be3560440a34</trackback:ping>
      <pingback:server>http://blog.jasonbunting.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.jasonbunting.com/PermaLink,guid,43b40452-8331-4160-a966-be3560440a34.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://blog.jasonbunting.com/CommentView,guid,43b40452-8331-4160-a966-be3560440a34.aspx</wfw:comment>
      <wfw:commentRss>http://blog.jasonbunting.com/SyndicationService.asmx/GetEntryCommentsRss?guid=43b40452-8331-4160-a966-be3560440a34</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
While writing in a word processor, you try to use code comments to comment-out a line
you have written which you are not quite sure belongs in the document.
</p>
        <p>
It's true - there I was, writing a talk I needed to give, and after writing a line
and thinking that I was not sure it belonged, I hit the 'Home' key to get to the beginning
of the line, and typed "//" and thought the line would go green, indicating it was
commented-out (which is what it does in Visual Studio). I need more sleep!
</p>
        <p>
Have you ever done something similar? 
</p>
        <img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=43b40452-8331-4160-a966-be3560440a34" />
      </body>
      <title>You know you are a geek when&amp;hellip;</title>
      <guid isPermaLink="false">http://blog.jasonbunting.com/PermaLink,guid,43b40452-8331-4160-a966-be3560440a34.aspx</guid>
      <link>http://blog.jasonbunting.com/2009/04/27/You+Know+You+Are+A+Geek+Whenhellip.aspx</link>
      <pubDate>Mon, 27 Apr 2009 00:27:00 GMT</pubDate>
      <description>&lt;p&gt;
While writing in a word processor, you try to use code comments to comment-out a line
you have written which you are not quite sure belongs in the document.
&lt;/p&gt;
&lt;p&gt;
It's true - there I was, writing a talk I needed to give, and after writing a line
and thinking that I was not sure it belonged, I hit the 'Home' key to get to the beginning
of the line, and typed "//" and thought the line would go green, indicating it was
commented-out (which is what it does in Visual Studio). I need more sleep!
&lt;/p&gt;
&lt;p&gt;
Have you ever done something similar? 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=43b40452-8331-4160-a966-be3560440a34" /&gt;</description>
      <comments>http://blog.jasonbunting.com/CommentView,guid,43b40452-8331-4160-a966-be3560440a34.aspx</comments>
      <category>Randomness</category>
      <category>Life</category>
    </item>
    <item>
      <trackback:ping>http://blog.jasonbunting.com/Trackback.aspx?guid=fd455c05-fe99-487f-b149-c313e534f704</trackback:ping>
      <pingback:server>http://blog.jasonbunting.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.jasonbunting.com/PermaLink,guid,fd455c05-fe99-487f-b149-c313e534f704.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://blog.jasonbunting.com/CommentView,guid,fd455c05-fe99-487f-b149-c313e534f704.aspx</wfw:comment>
      <wfw:commentRss>http://blog.jasonbunting.com/SyndicationService.asmx/GetEntryCommentsRss?guid=fd455c05-fe99-487f-b149-c313e534f704</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Stumbled upon this today, and while I am not too heavily using LINQ at the moment,
I know I will be at some point and this will come in handy; perhaps you might find
it useful as well. From Joseph Albahari's website, his intro to his page on 10 myths
about LINQ: 
</p>
        <blockquote>
          <p>
            <a title="10 Myths about LINQ" href="http://www.albahari.com/nutshell/10linqmyths.aspx" target="_blank">Here
are ten root causes</a> of the most common misunderstandings-distilled from many hundreds
of questions on <a title="MSDN's LINQ Project (General) Forum" href="http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/threads/" target="_blank">the
LINQ forums</a>.
</p>
        </blockquote>
        <p>
In case you want it, I created <a title="10 LINQ Myths (PDF)" href="http://cid-559790ad653fc810.skydrive.live.com/self.aspx/Dev/blog/C%7C3%203.0%20in%20a%20Nutshell%20-%2010%20LINQ%20Myths.pdf" target="_blank">a
PDF of the same page</a>, cleaned up a bit.
</p>
        <p>
Here are the 10, presented with only their descriptions:
</p>
        <ol>
          <li>
All LINQ queries must start with the 'var' keyword. In fact, the very purpose of the
'var' keyword is to start a LINQ query! 
<br /></li>
          <li>
All LINQ queries must use query syntax. 
<br /></li>
          <li>
To retrieve all customers from the customer table, you must perform a query similar
to the following: 
<br />
       var query = from c in db.Customers select c; 
<br /></li>
          <li>
To reproduce a SQL query in LINQ, you must make the LINQ query look as similar as
possible to the SQL query. 
<br /></li>
          <li>
To do joins efficiently in LINQ, you must use the join keyword. 
<br /></li>
          <li>
Because SQL emits flat result sets, LINQ queries must be structured to emit flat result
sets, too. 
<br /></li>
          <li>
To do outer joins in LINQ to SQL, you must always use DefaultIfEmpty(). 
<br /></li>
          <li>
A LINQ to SQL query will be executed in one round-trip only if the query was built
in a single step. 
<br /></li>
          <li>
A method cannot return a query, if the query ends in the 'new' operator. 
<br /></li>
          <li>
The best way to use LINQ to SQL is to instantiate a single DataContext to a static
property, and use that shared instance for the life of the application. 
</li>
        </ol>
Brothers Joseph Albahari &amp; Ben Albahari are the authors of "<a title="Amazon.com - C# 3.0 in a Nutshell, 3rd Edition" href="http://www.amazon.com/gp/product/0596527578?ie=UTF8&amp;tag=cinanu-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596527578" target="_blank">C#
3.0 in a Nutshell, 3rd Edition</a>," among other books published by <a title="O'Reilly Media" href="http://oreilly.com/" target="_blank">my
favorite book publisher</a>. <img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=fd455c05-fe99-487f-b149-c313e534f704" /></body>
      <title>LINQ: 10 Myths</title>
      <guid isPermaLink="false">http://blog.jasonbunting.com/PermaLink,guid,fd455c05-fe99-487f-b149-c313e534f704.aspx</guid>
      <link>http://blog.jasonbunting.com/2009/04/21/LINQ+10+Myths.aspx</link>
      <pubDate>Tue, 21 Apr 2009 22:12:26 GMT</pubDate>
      <description>&lt;p&gt;
Stumbled upon this today, and while I am not too heavily using LINQ at the moment,
I know I will be at some point and this will come in handy; perhaps you might find
it useful as well. From Joseph Albahari's website, his intro to his page on 10 myths
about LINQ: 
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;a title="10 Myths about LINQ" href="http://www.albahari.com/nutshell/10linqmyths.aspx" target="_blank"&gt;Here
are ten root causes&lt;/a&gt; of the most common misunderstandings-distilled from many hundreds
of questions on &lt;a title="MSDN's LINQ Project (General) Forum" href="http://social.msdn.microsoft.com/forums/en-US/linqprojectgeneral/threads/" target="_blank"&gt;the
LINQ forums&lt;/a&gt;.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
In case you want it, I created &lt;a title="10 LINQ Myths (PDF)" href="http://cid-559790ad653fc810.skydrive.live.com/self.aspx/Dev/blog/C%7C3%203.0%20in%20a%20Nutshell%20-%2010%20LINQ%20Myths.pdf" target="_blank"&gt;a
PDF of the same page&lt;/a&gt;, cleaned up a bit.
&lt;/p&gt;
&lt;p&gt;
Here are the 10, presented with only their descriptions:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
All LINQ queries must start with the 'var' keyword. In fact, the very purpose of the
'var' keyword is to start a LINQ query! 
&lt;br&gt;
&lt;/li&gt;
&lt;li&gt;
All LINQ queries must use query syntax. 
&lt;br&gt;
&lt;/li&gt;
&lt;li&gt;
To retrieve all customers from the customer table, you must perform a query similar
to the following: 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var query = from c in db.Customers select c; 
&lt;br&gt;
&lt;/li&gt;
&lt;li&gt;
To reproduce a SQL query in LINQ, you must make the LINQ query look as similar as
possible to the SQL query. 
&lt;br&gt;
&lt;/li&gt;
&lt;li&gt;
To do joins efficiently in LINQ, you must use the join keyword. 
&lt;br&gt;
&lt;/li&gt;
&lt;li&gt;
Because SQL emits flat result sets, LINQ queries must be structured to emit flat result
sets, too. 
&lt;br&gt;
&lt;/li&gt;
&lt;li&gt;
To do outer joins in LINQ to SQL, you must always use DefaultIfEmpty(). 
&lt;br&gt;
&lt;/li&gt;
&lt;li&gt;
A LINQ to SQL query will be executed in one round-trip only if the query was built
in a single step. 
&lt;br&gt;
&lt;/li&gt;
&lt;li&gt;
A method cannot return a query, if the query ends in the 'new' operator. 
&lt;br&gt;
&lt;/li&gt;
&lt;li&gt;
The best way to use LINQ to SQL is to instantiate a single DataContext to a static
property, and use that shared instance for the life of the application. 
&lt;/li&gt;
&lt;/ol&gt;
Brothers Joseph Albahari &amp;amp; Ben Albahari are the authors of "&lt;a title="Amazon.com - C# 3.0 in a Nutshell, 3rd Edition" href="http://www.amazon.com/gp/product/0596527578?ie=UTF8&amp;amp;tag=cinanu-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=0596527578" target="_blank"&gt;C#
3.0 in a Nutshell, 3rd Edition&lt;/a&gt;," among other books published by &lt;a title="O'Reilly Media" href="http://oreilly.com/" target="_blank"&gt;my
favorite book publisher&lt;/a&gt;. &lt;img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=fd455c05-fe99-487f-b149-c313e534f704" /&gt;</description>
      <comments>http://blog.jasonbunting.com/CommentView,guid,fd455c05-fe99-487f-b149-c313e534f704.aspx</comments>
      <category>C#</category>
    </item>
    <item>
      <trackback:ping>http://blog.jasonbunting.com/Trackback.aspx?guid=9531e162-1571-4671-9785-af47866e8b9f</trackback:ping>
      <pingback:server>http://blog.jasonbunting.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.jasonbunting.com/PermaLink,guid,9531e162-1571-4671-9785-af47866e8b9f.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://blog.jasonbunting.com/CommentView,guid,9531e162-1571-4671-9785-af47866e8b9f.aspx</wfw:comment>
      <wfw:commentRss>http://blog.jasonbunting.com/SyndicationService.asmx/GetEntryCommentsRss?guid=9531e162-1571-4671-9785-af47866e8b9f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I want you to look at the following code and <em>try not to think too hard</em>. There
is really only one basic assumption even worth mentioning, which is that &gt; 99.999%
of the time, you look at source code in Visual Studio (specifically, Visual Studio
2008, not that it matters).
</p>
        <p>
Here is the code we will be discussing for the moment - pretend you are one of my
coworkers reading it for the first time, and you need to understand what is going
on:
</p>
        <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
          <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 1:</span>
              <span style="color: rgb(0, 128, 0);">//
...a handful of lines into a method...</span>
            </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 2:</span> webGrid.Columns
= WebGridDefinitions.QuarterlyReportColumns(linkUrl);</pre>
          </div>
        </div>
        <p>
Now, of what type is the variable <font face="Courier New" size="2">webGrid</font>? 
<br />
How about <font face="Courier New" size="2">linkUrl</font>? 
<br />
I would be willing to bet you may be able to guess, even at this point. 
<br /><br /><br />
Now, let's say you are still not 100% sure, so you scroll up the method definition
a bit to find out, and you find this code: 
</p>
        <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
          <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 1:</span> var
linkUrl = htmlHelper.GetVirtualPath(<span style="color: rgb(0, 96, 128);">"MyAction"</span>, <span style="color: rgb(0, 96, 128);">"MyController"</span>);</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 2:</span> var
webGrid = <span style="color: rgb(0, 0, 255);">new</span> WebGrid(someObject, someData);</pre>
          </div>
        </div>
        <p>
Now, of what type is the variable <font face="Courier New" size="2">webGrid</font>? 
<br />
How about <font face="Courier New" size="2">linkUrl</font>? 
<br />
If you don't know at this point, there is little hope for you. 
<br /><br /><br />
Let's say that instead of the previous bit of code, you find this: 
</p>
        <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
          <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 1:</span>
              <span style="color: rgb(0, 0, 255);">string</span> linkUrl
= htmlHelper.GetVirtualPath(<span style="color: rgb(0, 96, 128);">"MyAction"</span>, <span style="color: rgb(0, 96, 128);">"MyController"</span>);</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 2:</span> WebGrid
webGrid = <span style="color: rgb(0, 0, 255);">new</span> WebGrid(someObject, someData);</pre>
          </div>
        </div>
        <p>
          <em>Now </em>of what type is the variable <font face="Courier New" size="2">webGrid</font>? 
<br />
How about <font face="Courier New" size="2">linkUrl</font>?  
<br />
How is this code <em>any</em> more clear than the code which uses the implicitly-typed
variable declaration? Is <a title="Department of Declaration Redundancy Department" href="http://www.codinghorror.com/blog/archives/001136.html" target="_blank"><strong>the
redundancy</strong></a> really that useful? <em>Really?!</em><br /></p>
        <p>
The only argument I am even willing to consider here is that, somehow, you are not
sure what type <font face="Courier New" size="2">htmlHelper.GetVirtualPath()</font> returns,
and thus the variable <font face="Courier New" size="2">linkUrl</font> is a bit ambiguous.
But, remember the assumption we began with? You have no excuse now, unless you just
started using Visual Studio 5 minutes ago and are not yet familiar with the power
of Intellisense.
</p>
        <p>
I posit that using implicitly-typed variable declarations via the <font face="Courier New" size="2">var</font> keyword
is <em>generally</em> easier to read and maintain than being explicit (and redundant)
in declaring variables.
</p>
        <p>
Now, one's personal taste can make this argument somewhat moot, since you can still
get the job done either way, but I would argue that it isn't worth pushing your personal
tastes on others if they are comfortable with either method. If you want to stay behind
the times and turn into a dinosaur, that's fine by me, but don't force me into the
same fate because you want to push your subjective tastes on others for your comfort.
</p>
        <p>
          <img alt="smile_tongue" src="http://spaces.live.com/rte/emoticons/smile_tongue.gif" />
        </p>
        <p>
          <em>By the way, the </em>
          <font face="Courier New" size="2">WebGrid</font>
          <em> type
here is not a standard type, but that isn't the point. Whatever a "WebGrid" is in
this code, it's only as far away as "<a title="How to: Search for Objects, Definitions, and References (Symbols) @ MSDN" href="http://msdn.microsoft.com/en-us/library/4sadchd3.aspx" target="_blank"><strong>Go
To Definition</strong></a>."</em>
        </p>
        <img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=9531e162-1571-4671-9785-af47866e8b9f" />
      </body>
      <title>C# Variable Declaration Idiocy</title>
      <guid isPermaLink="false">http://blog.jasonbunting.com/PermaLink,guid,9531e162-1571-4671-9785-af47866e8b9f.aspx</guid>
      <link>http://blog.jasonbunting.com/2009/04/04/C+Variable+Declaration+Idiocy.aspx</link>
      <pubDate>Sat, 04 Apr 2009 07:24:50 GMT</pubDate>
      <description>&lt;p&gt;
I want you to look at the following code and &lt;em&gt;try not to think too hard&lt;/em&gt;. There
is really only one basic assumption even worth mentioning, which is that &amp;gt; 99.999%
of the time, you look at source code in Visual Studio (specifically, Visual Studio
2008, not that it matters).
&lt;/p&gt;
&lt;p&gt;
Here is the code we will be discussing for the moment - pretend you are one of my
coworkers reading it for the first time, and you need to understand what is going
on:
&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 1:&lt;/span&gt; &lt;span style="color: rgb(0, 128, 0);"&gt;//
...a handful of lines into a method...&lt;/span&gt;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 2:&lt;/span&gt; webGrid.Columns
= WebGridDefinitions.QuarterlyReportColumns(linkUrl);&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
Now, of what type is the variable &lt;font face="Courier New" size="2"&gt;webGrid&lt;/font&gt;? 
&lt;br&gt;
How about &lt;font face="Courier New" size="2"&gt;linkUrl&lt;/font&gt;? 
&lt;br&gt;
I would be willing to bet you may be able to guess, even at this point. 
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Now, let's say you are still not 100% sure, so you scroll up the method definition
a bit to find out, and you find this code: 
&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 1:&lt;/span&gt; var
linkUrl = htmlHelper.GetVirtualPath(&lt;span style="color: rgb(0, 96, 128);"&gt;"MyAction"&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;"MyController"&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 2:&lt;/span&gt; var
webGrid = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; WebGrid(someObject, someData);&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
Now, of what type is the variable &lt;font face="Courier New" size="2"&gt;webGrid&lt;/font&gt;? 
&lt;br&gt;
How about &lt;font face="Courier New" size="2"&gt;linkUrl&lt;/font&gt;? 
&lt;br&gt;
If you don't know at this point, there is little hope for you. 
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Let's say that instead of the previous bit of code, you find this: 
&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; linkUrl
= htmlHelper.GetVirtualPath(&lt;span style="color: rgb(0, 96, 128);"&gt;"MyAction"&lt;/span&gt;, &lt;span style="color: rgb(0, 96, 128);"&gt;"MyController"&lt;/span&gt;);&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 2:&lt;/span&gt; WebGrid
webGrid = &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; WebGrid(someObject, someData);&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;em&gt;Now &lt;/em&gt;of what type is the variable &lt;font face="Courier New" size="2"&gt;webGrid&lt;/font&gt;? 
&lt;br&gt;
How about &lt;font face="Courier New" size="2"&gt;linkUrl&lt;/font&gt;?&amp;nbsp; 
&lt;br&gt;
How is this code &lt;em&gt;any&lt;/em&gt; more clear than the code which uses the implicitly-typed
variable declaration? Is &lt;a title="Department of Declaration Redundancy Department" href="http://www.codinghorror.com/blog/archives/001136.html" target="_blank"&gt;&lt;strong&gt;the
redundancy&lt;/strong&gt;&lt;/a&gt; really that useful? &lt;em&gt;Really?!&lt;/em&gt; 
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
The only argument I am even willing to consider here is that, somehow, you are not
sure what type &lt;font face="Courier New" size="2"&gt;htmlHelper.GetVirtualPath()&lt;/font&gt; returns,
and thus the variable &lt;font face="Courier New" size="2"&gt;linkUrl&lt;/font&gt; is a bit ambiguous.
But, remember the assumption we began with? You have no excuse now, unless you just
started using Visual Studio 5 minutes ago and are not yet familiar with the power
of Intellisense.
&lt;/p&gt;
&lt;p&gt;
I posit that using implicitly-typed variable declarations via the &lt;font face="Courier New" size="2"&gt;var&lt;/font&gt; keyword
is &lt;em&gt;generally&lt;/em&gt; easier to read and maintain than being explicit (and redundant)
in declaring variables.
&lt;/p&gt;
&lt;p&gt;
Now, one's personal taste can make this argument somewhat moot, since you can still
get the job done either way, but I would argue that it isn't worth pushing your personal
tastes on others if they are comfortable with either method. If you want to stay behind
the times and turn into a dinosaur, that's fine by me, but don't force me into the
same fate because you want to push your subjective tastes on others for your comfort.
&lt;/p&gt;
&lt;p&gt;
&lt;img alt="smile_tongue" src="http://spaces.live.com/rte/emoticons/smile_tongue.gif"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;By the way, the &lt;/em&gt;&lt;font face="Courier New" size="2"&gt;WebGrid&lt;/font&gt;&lt;em&gt; type
here is not a standard type, but that isn't the point. Whatever a "WebGrid" is in
this code, it's only as far away as "&lt;a title="How to: Search for Objects, Definitions, and References (Symbols) @ MSDN" href="http://msdn.microsoft.com/en-us/library/4sadchd3.aspx" target="_blank"&gt;&lt;strong&gt;Go
To Definition&lt;/strong&gt;&lt;/a&gt;."&lt;/em&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=9531e162-1571-4671-9785-af47866e8b9f" /&gt;</description>
      <comments>http://blog.jasonbunting.com/CommentView,guid,9531e162-1571-4671-9785-af47866e8b9f.aspx</comments>
      <category>C#</category>
      <category>Work</category>
    </item>
    <item>
      <trackback:ping>http://blog.jasonbunting.com/Trackback.aspx?guid=5a2506a1-64c6-416d-af16-f33390de54fd</trackback:ping>
      <pingback:server>http://blog.jasonbunting.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.jasonbunting.com/PermaLink,guid,5a2506a1-64c6-416d-af16-f33390de54fd.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://blog.jasonbunting.com/CommentView,guid,5a2506a1-64c6-416d-af16-f33390de54fd.aspx</wfw:comment>
      <wfw:commentRss>http://blog.jasonbunting.com/SyndicationService.asmx/GetEntryCommentsRss?guid=5a2506a1-64c6-416d-af16-f33390de54fd</wfw:commentRss>
      <slash:comments>6</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Over the last 4 years, JavaScript has been critical to the majority of the web applications
that I have worked on; dealing with the logical organization of said files has always
been a less-than-satisfactory experience until about 2 years ago when I began using
the following techniques for a easier <em>design-time</em> experience.
</p>
        <h4>Page-Specific JavaScript Files
</h4>
        <p>
Let's say I have a page named foo.aspx and I have JavaScript specific to it contained
in a file - I name the .js file foo.aspx.js. Then, in a <em>base class</em> for the
pages of the application, I have the following code:
</p>
        <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 650px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
          <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 1:</span>
              <span style="color: rgb(0, 0, 255);">protected</span>
              <span style="color: rgb(0, 0, 255);">override</span>
              <span style="color: rgb(0, 0, 255);">void</span> OnLoad(EventArgs
e)</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 2:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 3:</span>
              <span style="color: rgb(0, 0, 255);">base</span>.OnLoad(e);</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 4:</span> AttachPageSpecificJavaScriptFile();</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 5:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 6:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 7:</span>
              <span style="color: rgb(0, 0, 255);">private</span>
              <span style="color: rgb(0, 0, 255);">void</span> AttachPageSpecificJavaScriptFile()</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 8:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 9:</span> var
appRelativeVirtualPath = <span style="color: rgb(0, 0, 255);">string</span>.Format(<span style="color: rgb(0, 96, 128);">"{0}.js"</span>,
TemplateControl.AppRelativeVirtualPath);</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 10:</span> RegisterJavaScriptFile(appRelativeVirtualPath);</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 11:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 12:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 13:</span>
              <span style="color: rgb(0, 0, 255);">protected</span>
              <span style="color: rgb(0, 0, 255);">void</span> RegisterJavaScriptFile(<span style="color: rgb(0, 0, 255);">string</span> appRelativeVirtualPath)</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 14:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 15:</span>
              <span style="color: rgb(0, 0, 255);">if</span> (JavaScriptFileExists(appRelativeVirtualPath))</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 16:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 17:</span>
              <span style="color: rgb(0, 0, 255);">string</span> url
= ResolveClientUrl(appRelativeVirtualPath);</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 18:</span> ClientScript.RegisterClientScriptInclude(url,
url);</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 19:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 20:</span> }</pre>
          </div>
        </div>
        <p>
Essentially, for each page in my application, the app will look for a *.aspx.js file
that matches the name of the page (in our example, foo.aspx.js) and place, within
the rendered page, a script tag referencing it.
</p>
        <p>
Since every request to a given page would need to check to see whether or not an associated
.js file existed, and considering the fact that checking with the file system each
time would be somewhat costly, I have the following code take care of checking and
then caching the results at the application level:
</p>
        <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 650px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
          <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 1:</span>
              <span style="color: rgb(0, 0, 255);">private</span> Dictionary&lt;<span style="color: rgb(0, 0, 255);">string</span>, <span style="color: rgb(0, 0, 255);">bool</span>&gt;
JavaScriptFileRegistry</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 2:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 3:</span> get</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 4:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 5:</span> var
javaScriptFileRegistry = Application[<span style="color: rgb(0, 96, 128);">"JavaScriptFileRegistry"</span>] <span style="color: rgb(0, 0, 255);">as</span> Dictionary&lt;<span style="color: rgb(0, 0, 255);">string</span>, <span style="color: rgb(0, 0, 255);">bool</span>&gt;;</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 6:</span>
              <span style="color: rgb(0, 0, 255);">if</span> (javaScriptFileRegistry
== <span style="color: rgb(0, 0, 255);">null</span>)</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 7:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 8:</span> javaScriptFileRegistry
= <span style="color: rgb(0, 0, 255);">new</span> Dictionary&lt;<span style="color: rgb(0, 0, 255);">string</span>, <span style="color: rgb(0, 0, 255);">bool</span>&gt;();</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 9:</span> Application[<span style="color: rgb(0, 96, 128);">"JavaScriptFileRegistry"</span>]
= javaScriptFileRegistry;</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 10:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 11:</span>
              <span style="color: rgb(0, 0, 255);">return</span> javaScriptFileRegistry;</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 12:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 13:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 14:</span>  </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 15:</span>
              <span style="color: rgb(0, 0, 255);">protected</span>
              <span style="color: rgb(0, 0, 255);">bool</span> JavaScriptFileExists(<span style="color: rgb(0, 0, 255);">string</span> appRelativeVirtualPath)</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 16:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 17:</span> var
registry = JavaScriptFileRegistry;</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 18:</span>
              <span style="color: rgb(0, 0, 255);">if</span> (registry.ContainsKey(appRelativeVirtualPath)
== <span style="color: rgb(0, 0, 255);">false</span>)</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 19:</span> {</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 20:</span> registry.Add(appRelativeVirtualPath,
File.Exists(Server.MapPath(appRelativeVirtualPath)));</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 21:</span> }</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 22:</span>
              <span style="color: rgb(0, 0, 255);">return</span> registry[appRelativeVirtualPath];</pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 23:</span> }</pre>
          </div>
        </div>
        <p>
        </p>
        <p>
To complete this, I have a registry hack that will cause any *.aspx.js files to collapse
underneath the *.aspx page in the solution explorer of Visual Studio (i.e. it will
hide underneath the page, just like the *.aspx.cs file does). Depending on the version
of Visual Studio you are using, the registry hack is different. Here are a couple
that I use with Windows XP (I don't know if they differ for Vista because I don't
use Vista) - copy each one into a text file and rename it with a .reg extension, then
execute the file.
</p>
        <h5>Visual Studio 2005
</h5>
        <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
          <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 1:</span> Windows
Registry Editor Version 5.00 </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 2:</span> [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Projects\{E24C65DC-7377-472b-9ABA-BC803B73C61A}\RelatedFiles\.aspx\.js] </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 3:</span> @=<span style="color: rgb(0, 96, 128);">""</span></pre>
          </div>
        </div>
        <h5>Visual Studio 2008
</h5>
        <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
          <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 1:</span> Windows
Registry Editor Version 5.00 </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 2:</span> [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Projects\{E24C65DC-7377-472b-9ABA-BC803B73C61A}\RelatedFiles\.aspx\.js] </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 3:</span> @=<span style="color: rgb(0, 96, 128);">""</span></pre>
          </div>
        </div>
        <p>
You will probably need to reboot your machine before these take effect. Also, the
nesting will only take place for newly-added .js files, any that you have which are
already named *.aspx.js can be nested by either re-adding them to the project or manually
modifying the .csproj file's XML.
</p>
        <p>
Anyway, that is how I do things and it really helps to keep things organized. I also
do all of this for user controls (ascx files) - with the above, it should be simple
enough to figure out how to do this for the user controls and ascx file extension.
</p>
        <p>
Hope this helps someone!
</p>
        <hr />
        <h4>UPDATE
</h4>
        <h5>Visual Studio 2010 (x64)
</h5>
        <div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
          <div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 1:</span> Windows
Registry Editor Version 5.00 </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);">
              <span style="color: rgb(96, 96, 96);"> 2:</span> [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0_Config\Projects\{E24C65DC-7377-472b-9ABA-BC803B73C61A}\RelatedFiles\.aspx\.js] </pre>
            <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">
              <span style="color: rgb(96, 96, 96);"> 3:</span> @=<span style="color: rgb(0, 96, 128);">""</span></pre>
          </div>
        </div>
        <img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=5a2506a1-64c6-416d-af16-f33390de54fd" />
      </body>
      <title>ASP.NET Web Forms &amp;amp; JavaScript: A Technique for file organization</title>
      <guid isPermaLink="false">http://blog.jasonbunting.com/PermaLink,guid,5a2506a1-64c6-416d-af16-f33390de54fd.aspx</guid>
      <link>http://blog.jasonbunting.com/2009/02/03/ASPNET+Web+Forms+Amp+JavaScript+A+Technique+For+File+Organization.aspx</link>
      <pubDate>Tue, 03 Feb 2009 21:21:51 GMT</pubDate>
      <description>&lt;p&gt;
Over the last 4 years, JavaScript has been critical to the majority of the web applications
that I have worked on; dealing with the logical organization of said files has always
been a less-than-satisfactory experience until about 2 years ago when I began using
the following techniques for a easier &lt;em&gt;design-time&lt;/em&gt; experience.
&lt;/p&gt;
&lt;h4&gt;Page-Specific JavaScript Files
&lt;/h4&gt;
&lt;p&gt;
Let's say I have a page named foo.aspx and I have JavaScript specific to it contained
in a file - I name the .js file foo.aspx.js. Then, in a &lt;em&gt;base class&lt;/em&gt; for the
pages of the application, I have the following code:
&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 650px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;override&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; OnLoad(EventArgs
e)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 2:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 3:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;base&lt;/span&gt;.OnLoad(e);&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 4:&lt;/span&gt; AttachPageSpecificJavaScriptFile();&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 5:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 6:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 7:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; AttachPageSpecificJavaScriptFile()&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 8:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 9:&lt;/span&gt; var
appRelativeVirtualPath = &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;.Format(&lt;span style="color: rgb(0, 96, 128);"&gt;"{0}.js"&lt;/span&gt;,
TemplateControl.AppRelativeVirtualPath);&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 10:&lt;/span&gt; RegisterJavaScriptFile(appRelativeVirtualPath);&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 11:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 12:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 13:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;void&lt;/span&gt; RegisterJavaScriptFile(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; appRelativeVirtualPath)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 14:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 15:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (JavaScriptFileExists(appRelativeVirtualPath))&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 16:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 17:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; url
= ResolveClientUrl(appRelativeVirtualPath);&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 18:&lt;/span&gt; ClientScript.RegisterClientScriptInclude(url,
url);&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 19:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 20:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
Essentially, for each page in my application, the app will look for a *.aspx.js file
that matches the name of the page (in our example, foo.aspx.js) and place, within
the rendered page, a script tag referencing it.
&lt;/p&gt;
&lt;p&gt;
Since every request to a given page would need to check to see whether or not an associated
.js file existed, and considering the fact that checking with the file system each
time would be somewhat costly, I have the following code take care of checking and
then caching the results at the application level:
&lt;/p&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 650px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 1:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;private&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt;&amp;gt;
JavaScriptFileRegistry&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 2:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 3:&lt;/span&gt; get&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 4:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 5:&lt;/span&gt; var
javaScriptFileRegistry = Application[&lt;span style="color: rgb(0, 96, 128);"&gt;"JavaScriptFileRegistry"&lt;/span&gt;] &lt;span style="color: rgb(0, 0, 255);"&gt;as&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt;&amp;gt;;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 6:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (javaScriptFileRegistry
== &lt;span style="color: rgb(0, 0, 255);"&gt;null&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 7:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 8:&lt;/span&gt; javaScriptFileRegistry
= &lt;span style="color: rgb(0, 0, 255);"&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt;&amp;gt;();&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 9:&lt;/span&gt; Application[&lt;span style="color: rgb(0, 96, 128);"&gt;"JavaScriptFileRegistry"&lt;/span&gt;]
= javaScriptFileRegistry;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 10:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 11:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; javaScriptFileRegistry;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 12:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 13:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 14:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 15:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;protected&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;bool&lt;/span&gt; JavaScriptFileExists(&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt; appRelativeVirtualPath)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 16:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 17:&lt;/span&gt; var
registry = JavaScriptFileRegistry;&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 18:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;if&lt;/span&gt; (registry.ContainsKey(appRelativeVirtualPath)
== &lt;span style="color: rgb(0, 0, 255);"&gt;false&lt;/span&gt;)&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 19:&lt;/span&gt; {&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 20:&lt;/span&gt; registry.Add(appRelativeVirtualPath,
File.Exists(Server.MapPath(appRelativeVirtualPath)));&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 21:&lt;/span&gt; }&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 22:&lt;/span&gt; &lt;span style="color: rgb(0, 0, 255);"&gt;return&lt;/span&gt; registry[appRelativeVirtualPath];&lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 23:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
To complete this, I have a registry hack that will cause any *.aspx.js files to collapse
underneath the *.aspx page in the solution explorer of Visual Studio (i.e. it will
hide underneath the page, just like the *.aspx.cs file does). Depending on the version
of Visual Studio you are using, the registry hack is different. Here are a couple
that I use with Windows XP (I don't know if they differ for Vista because I don't
use Vista) - copy each one into a text file and rename it with a .reg extension, then
execute the file.
&lt;/p&gt;
&lt;h5&gt;Visual Studio 2005
&lt;/h5&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 1:&lt;/span&gt; Windows
Registry Editor Version 5.00 &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 2:&lt;/span&gt; [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Projects\{E24C65DC-7377-472b-9ABA-BC803B73C61A}\RelatedFiles\.aspx\.js] &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 3:&lt;/span&gt; @=&lt;span style="color: rgb(0, 96, 128);"&gt;""&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h5&gt;Visual Studio 2008
&lt;/h5&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 1:&lt;/span&gt; Windows
Registry Editor Version 5.00 &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 2:&lt;/span&gt; [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Projects\{E24C65DC-7377-472b-9ABA-BC803B73C61A}\RelatedFiles\.aspx\.js] &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 3:&lt;/span&gt; @=&lt;span style="color: rgb(0, 96, 128);"&gt;""&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
You will probably need to reboot your machine before these take effect. Also, the
nesting will only take place for newly-added .js files, any that you have which are
already named *.aspx.js can be nested by either re-adding them to the project or manually
modifying the .csproj file's XML.
&lt;/p&gt;
&lt;p&gt;
Anyway, that is how I do things and it really helps to keep things organized. I also
do all of this for user controls (ascx files) - with the above, it should be simple
enough to figure out how to do this for the user controls and ascx file extension.
&lt;/p&gt;
&lt;p&gt;
Hope this helps someone!
&lt;/p&gt;
&lt;hr&gt;
&lt;h4&gt;UPDATE
&lt;/h4&gt;
&lt;h5&gt;Visual Studio 2010 (x64)
&lt;/h5&gt;
&lt;div style="border: 1px solid gray; margin: 20px 0px 10px; padding: 4px; overflow: auto; font-size: 8pt; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 1:&lt;/span&gt; Windows
Registry Editor Version 5.00 &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: rgb(244, 244, 244);"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 2:&lt;/span&gt; [HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0_Config\Projects\{E24C65DC-7377-472b-9ABA-BC803B73C61A}\RelatedFiles\.aspx\.js] &lt;/pre&gt;
&lt;pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"&gt;&lt;span style="color: rgb(96, 96, 96);"&gt; 3:&lt;/span&gt; @=&lt;span style="color: rgb(0, 96, 128);"&gt;""&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=5a2506a1-64c6-416d-af16-f33390de54fd" /&gt;</description>
      <comments>http://blog.jasonbunting.com/CommentView,guid,5a2506a1-64c6-416d-af16-f33390de54fd.aspx</comments>
      <category>ASP.NET</category>
      <category>C#</category>
      <category>JavaScript</category>
      <category>Work</category>
    </item>
    <item>
      <trackback:ping>http://blog.jasonbunting.com/Trackback.aspx?guid=897fba72-df01-45c1-8206-8135d917235e</trackback:ping>
      <pingback:server>http://blog.jasonbunting.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.jasonbunting.com/PermaLink,guid,897fba72-df01-45c1-8206-8135d917235e.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://blog.jasonbunting.com/CommentView,guid,897fba72-df01-45c1-8206-8135d917235e.aspx</wfw:comment>
      <wfw:commentRss>http://blog.jasonbunting.com/SyndicationService.asmx/GetEntryCommentsRss?guid=897fba72-df01-45c1-8206-8135d917235e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <style type="text/css">


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
I sure hope so! <a href="http://blah.winsmarts.com/2006/05/17/demystifying-c-30--part-2-anonymous-types.aspx" target="_blank">I
noticed this quite some time ago</a> when I first saw the syntax for anonymous types
in C#. Being a lover of JavaScript, I quite like the ability to do things in C# in
a manner consistent with the syntax I am used to using in JavaScript (my current favorite
programming language, especially thanks to <a title="MochiKit makes JavaScript suck less!" href="http://www.mochikit.com/" target="_blank">MochiKit</a>).
The syntax I refer to is partly alluded to in <a href="http://weblogs.asp.net/leftslipper/archive/2007/09/24/using-c-3-0-anonymous-types-as-dictionaries.aspx" target="_blank">this
post by Eilon Lipton</a> (first time I have ever heard of Eilon), where he talks about
substituting an anonymous type for a <span class="csharpcode">Dictionary&lt;<span class="kwrd">string</span>, <span class="kwrd">string</span>&gt;</span>,
using said Dictionary for setting attributes on HTML tags he is creating in C#. Sound
familiar? I mentioned something similar in <a href="http://jasonbunting.com/blahg/PermaLink,guid,ca16cf2b-c604-4817-ba9c-1b2a1f762327.aspx" target="_blank">my
post yesterday</a>.
</p>
        <p>
To illustrate the syntax I keep referring to, here is what I am used to doing in JavaScript,
particularly with MochiKit - let's say I want to create a div element programmatically
(and let's spit it out as HTML so we can better get the gist of things):
</p>
        <pre class="csharpcode">
          <span class="kwrd">
          </span>toHTML(DIV({id:<span class="str">"myDiv"</span>, <span class="kwrd">class</span>:<span class="str">"myCssClass"</span>},
P({ style:<span class="str">"font-weight:bold"</span> }, <span class="str">"Hello
World!"</span>)));</pre>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
The HTML rendered looks like:
</p>
        <pre class="csharpcode">
          <span class="kwrd">&lt;</span>
          <span class="html">div</span>
          <span class="attr">class</span>
          <span class="kwrd">="myCssClass"</span>
          <span class="attr">id</span>
          <span class="kwrd">="myDiv"</span>
          <span class="kwrd">&gt;</span>
          <span class="kwrd">&lt;</span>
          <span class="html">p</span>
          <span class="attr">style</span>
          <span class="kwrd">="font-weight:
bold;"</span>
          <span class="kwrd">&gt;</span>Hello World!<span class="kwrd">&lt;/</span><span class="html">p</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span></pre>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
So, rather than declaring a the JavaScript function "DIV" or "P" (which create div
and paragraph DOM elements, respectively) with every possible option as a parameter
to said function (e.g. id, style, class, etc.), you simply pass in an anonymous object
which contains values for the properties you care about setting. This is a fairly
typical way of doing things in JavaScript, and despite the protests from the academic
portion of my brain as well as <a href="http://blogs.msdn.com/abhinaba/archive/2005/09/19/471101.aspx" target="_blank">other
developers</a>, I would love to be able to do the same in C#.
</p>
        <p>
 
</p>
        <div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:7638ac75-7195-4635-b798-3d5806b5e096" style="margin: 0px; padding: 0px; display: inline;">Technorati
Tags: <a href="http://technorati.com/tags/JavaScript/" rel="tag">JavaScript</a> , <a href="http://technorati.com/tags/C#/" rel="tag">C#</a> , <a href="http://technorati.com/tags/ASP.NET/" rel="tag">ASP.NET</a> , <a href="http://technorati.com/tags/Anonymous%20Types/" rel="tag">Anonymous
Types</a></div>
        <img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=897fba72-df01-45c1-8206-8135d917235e" />
      </body>
      <title>Is C# becoming more like JavaScript?</title>
      <guid isPermaLink="false">http://blog.jasonbunting.com/PermaLink,guid,897fba72-df01-45c1-8206-8135d917235e.aspx</guid>
      <link>http://blog.jasonbunting.com/2007/11/01/Is+C+Becoming+More+Like+JavaScript.aspx</link>
      <pubDate>Thu, 01 Nov 2007 18:38:15 GMT</pubDate>
      <description>&lt;p&gt;
&lt;style type="text/css"&gt;


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
I sure hope so! &lt;a href="http://blah.winsmarts.com/2006/05/17/demystifying-c-30--part-2-anonymous-types.aspx" target="_blank"&gt;I
noticed this quite some time ago&lt;/a&gt; when I first saw the syntax for anonymous types
in C#. Being a lover of JavaScript, I quite like the ability to do things in C# in
a manner consistent with the syntax I am used to using in JavaScript (my current favorite
programming language, especially thanks to &lt;a title="MochiKit makes JavaScript suck less!" href="http://www.mochikit.com/" target="_blank"&gt;MochiKit&lt;/a&gt;).
The syntax I refer to is partly alluded to in &lt;a href="http://weblogs.asp.net/leftslipper/archive/2007/09/24/using-c-3-0-anonymous-types-as-dictionaries.aspx" target="_blank"&gt;this
post by Eilon Lipton&lt;/a&gt; (first time I have ever heard of Eilon), where he talks about
substituting an anonymous type for a &lt;span class="csharpcode"&gt;Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;&lt;/span&gt;,
using said Dictionary for setting attributes on HTML tags he is creating in C#. Sound
familiar? I mentioned something similar in &lt;a href="http://jasonbunting.com/blahg/PermaLink,guid,ca16cf2b-c604-4817-ba9c-1b2a1f762327.aspx" target="_blank"&gt;my
post yesterday&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
To illustrate the syntax I keep referring to, here is what I am used to doing in JavaScript,
particularly with MochiKit - let's say I want to create a div element programmatically
(and let's spit it out as HTML so we can better get the gist of things):
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt; &lt;/span&gt;toHTML(DIV({id:&lt;span class="str"&gt;"myDiv"&lt;/span&gt;, &lt;span class="kwrd"&gt;class&lt;/span&gt;:&lt;span class="str"&gt;"myCssClass"&lt;/span&gt;},
P({ style:&lt;span class="str"&gt;"font-weight:bold"&lt;/span&gt; }, &lt;span class="str"&gt;"Hello
World!"&lt;/span&gt;)));&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
The HTML rendered looks like:
&lt;/p&gt;
&lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;="myCssClass"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="myDiv"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;p&lt;/span&gt; &lt;span class="attr"&gt;style&lt;/span&gt;&lt;span class="kwrd"&gt;="font-weight:
bold;"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Hello World!&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;p&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
So, rather than declaring a the JavaScript function "DIV" or "P" (which create div
and paragraph DOM elements, respectively) with every possible option as a parameter
to said function (e.g. id, style, class, etc.), you simply pass in an anonymous object
which contains values for the properties you care about setting. This is a fairly
typical way of doing things in JavaScript, and despite the protests from the academic
portion of my brain as well as &lt;a href="http://blogs.msdn.com/abhinaba/archive/2005/09/19/471101.aspx" target="_blank"&gt;other
developers&lt;/a&gt;, I would love to be able to do the same in C#.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:7638ac75-7195-4635-b798-3d5806b5e096" style="margin: 0px; padding: 0px; display: inline;"&gt;Technorati
Tags: &lt;a href="http://technorati.com/tags/JavaScript/" rel="tag"&gt;JavaScript&lt;/a&gt; , &lt;a href="http://technorati.com/tags/C#/" rel="tag"&gt;C#&lt;/a&gt; , &lt;a href="http://technorati.com/tags/ASP.NET/" rel="tag"&gt;ASP.NET&lt;/a&gt; , &lt;a href="http://technorati.com/tags/Anonymous%20Types/" rel="tag"&gt;Anonymous
Types&lt;/a&gt; 
&lt;/div&gt;
&lt;img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=897fba72-df01-45c1-8206-8135d917235e" /&gt;</description>
      <comments>http://blog.jasonbunting.com/CommentView,guid,897fba72-df01-45c1-8206-8135d917235e.aspx</comments>
      <category>ASP.NET</category>
      <category>C#</category>
      <category>JavaScript</category>
    </item>
    <item>
      <trackback:ping>http://blog.jasonbunting.com/Trackback.aspx?guid=ca16cf2b-c604-4817-ba9c-1b2a1f762327</trackback:ping>
      <pingback:server>http://blog.jasonbunting.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.jasonbunting.com/PermaLink,guid,ca16cf2b-c604-4817-ba9c-1b2a1f762327.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://blog.jasonbunting.com/CommentView,guid,ca16cf2b-c604-4817-ba9c-1b2a1f762327.aspx</wfw:comment>
      <wfw:commentRss>http://blog.jasonbunting.com/SyndicationService.asmx/GetEntryCommentsRss?guid=ca16cf2b-c604-4817-ba9c-1b2a1f762327</wfw:commentRss>
      <slash:comments>11</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Since learning about <a href="http://www.subsonicproject.com/" target="_blank">the
SubSonic project</a> last week, I have spent a bit of time reading up on it, watching
screencasts about it, playing with it, and reading <a href="http://blog.wekeroad.com/" target="_blank">the
blog of its creator, Rob Conery</a>. In his post "<a href="http://blog.wekeroad.com/2007/10/25/how-mvc-jquery-and-subsonic-will-make-you-smile/" target="_blank">How
MVC, jQuery, and SubSonic Will Make You Smile</a>," Rob talks about the use of .NET
3.5's extension methods, in particular extending a <span style="color: rgb(43, 145, 175);">Dictionary</span>&lt;<span style="color: rgb(0, 0, 255);">string</span>, <span style="color: rgb(0, 0, 255);">string</span>&gt;
to return HTML for a drop down list (HTML select); here is what his version of the
extension method looks like:
</p>
        <p>
 
</p>
        <div class="csharpcode">
          <div class="csharpcode">
            <pre class="alt">
              <span class="lnum"> 1: </span>
              <span class="kwrd">public</span>
              <span class="kwrd">static</span>
              <span class="kwrd">string</span> ToHtmlSelect(<span class="kwrd">this</span> Dictionary&lt;<span class="kwrd">string</span>, <span class="kwrd">string</span>&gt;
listItems, <span class="kwrd">string</span> name,<br /><span class="kwrd">object</span> selectedValue, <span class="kwrd">object</span> attributes)</pre>
            <pre>
              <span class="lnum"> 2: </span>{</pre>
            <pre class="alt">
              <span class="lnum"> 3: </span>
              <span class="rem">// input formats</span>
            </pre>
            <pre>
              <span class="lnum"> 4: </span>
              <span class="kwrd">string</span> selectFormat
= <span class="str">"&lt;select name='{0}' id='{0}' {1}&gt;\r\n{2}\r\n &lt;/select&gt;"</span>;</pre>
            <pre class="alt">
              <span class="lnum"> 5: </span>
              <span class="kwrd">string</span> optionFormat
= <span class="str">"\t&lt;option value='{0}' {1}&gt;{2}&lt;/option&gt;\r\n"</span>;</pre>
            <pre>
              <span class="lnum"> 6: </span> </pre>
            <pre class="alt">
              <span class="lnum"> 7: </span>
              <span class="rem">// output</span>
            </pre>
            <pre>
              <span class="lnum"> 8: </span> StringBuilder sb = <span class="kwrd">new</span> StringBuilder();</pre>
            <pre class="alt">
              <span class="lnum"> 9: </span> </pre>
            <pre>
              <span class="lnum"> 10: </span>
              <span class="kwrd">foreach</span> (<span class="kwrd">string</span> s <span class="kwrd">in</span> listItems.Keys)</pre>
            <pre class="alt">
              <span class="lnum"> 11: </span> {</pre>
            <pre>
              <span class="lnum"> 12: </span>
              <span class="kwrd">string</span> selectedFlag
= <span class="str">""</span>;</pre>
            <pre class="alt">
              <span class="lnum"> 13: </span>
              <span class="kwrd">string</span> text
= listItems[s];</pre>
            <pre>
              <span class="lnum"> 14: </span>
              <span class="kwrd">string</span>
              <span class="kwrd">value</span> =
s;</pre>
            <pre class="alt">
              <span class="lnum"> 15: </span>
              <span class="kwrd">if</span> (<span class="kwrd">value</span>.ToLower().Equals(selectedValue.ToString().ToLower()))</pre>
            <pre>
              <span class="lnum"> 16: </span> selectedFlag = <span class="str">"selected=true"</span>;</pre>
            <pre class="alt">
              <span class="lnum"> 17: </span> sb.AppendFormat(optionFormat, s.ToString(),
selectedFlag, text);</pre>
            <pre>
              <span class="lnum"> 18: </span> }</pre>
            <pre class="alt">
              <span class="lnum"> 19: </span>
              <span class="kwrd">string</span> result
= <span class="kwrd">string</span>.Format(selectFormat, name, attributes.ToAttributeList(),
sb.ToString());</pre>
            <pre>
              <span class="lnum"> 20: </span>
              <span class="kwrd">return</span> result;</pre>
            <pre class="alt">
              <span class="lnum"> 21: </span>}</pre>
          </div>
          <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
          <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
          <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
          <a href="http://11011.net/software/vspaste">
          </a>
          <a href="http://11011.net/software/vspaste">
          </a>
          <pre>
          </pre>
        </div>
        <pre class="code">
        </pre>
        <p>
 
</p>
        <p>
He also mentions that (on line 19) there is another extension method that "hangs off
the object class" which basically enumerates all of the properties of an object, creating
a name/value pair attribute list. He doesn't give the code of that extension method,
which he states "is ScottGu magic at work and something he <a href="http://weblogs.asp.net/scottgu/archive/2007/10/14/asp-net-mvc-framework.aspx" target="_blank">shows
in his MVC demos</a>." I have yet to watch those demos myself, but the code is probably
something akin to this:
</p>
        <p>
 
</p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">static</span>
            <span class="kwrd">string</span> ToAttributeList(<span class="kwrd">this</span><span class="kwrd">object</span> attributes) </pre>
          <pre>
            <span class="lnum"> 2: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span> StringBuilder sb = <span class="kwrd">new</span> StringBuilder();</pre>
          <pre>
            <span class="lnum"> 4: </span>
            <span class="kwrd">foreach</span> (PropertyDescriptor
property <span class="kwrd">in</span> TypeDescriptor.GetProperties(attributes)) </pre>
          <pre class="alt">
            <span class="lnum"> 5: </span> {</pre>
          <pre>
            <span class="lnum"> 6: </span> sb.AppendFormat(<span class="str">"{0}='{1}' "</span>,
property.Name, property.GetValue(attributes).ToString());</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span> }</pre>
          <pre>
            <span class="lnum"> 8: </span>
            <span class="kwrd">return</span> sb.ToString();</pre>
          <pre class="alt">
            <span class="lnum"> 9: </span>}</pre>
        </div>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
 
</p>
        <p>
This allows you to pass anonymous types, specifying what might normally be optional
parameters, a la something I have been doing in JavaScript for a while using <a title="MochiKit - It makes JavaScript suck less!" href="http://www.mochikit.com/" target="_blank">MochiKit</a> (other
JavaScript libs exploit the same literal JavaScript object notation in their function
signatures). The idea is that you don't need to have a structured method signature
that accepts all possible options - you can pass in what you want to specify as a
part of an anonymous object. This will make more sense if you have spent any time
doing this in JavaScript or want to wait a moment and read on.
</p>
        <p>
Anyway, the whole reason I was even posting on this subject is because of a comment
made on Rob's post by one Joe Chung, wherein he states:
</p>
        <blockquote>
          <p>
            <em>"Seeing StringBuilder-generated HTML makes me sad for the future of ASP.NET. Object-oriented
ASP spaghetti code is still spaghetti code."</em>
          </p>
        </blockquote>
        <p>
He is referring to the string hacking done in the ToHtmlSelect extension method. I
too don't care for it, and simply wanted to show a nicer way of doing this, which
leverages <strong>objects we already have access to</strong> in ASP.NET which do that
grunt work for us.
</p>
        <p>
Here is my version of Rob's method (which I still have issues with, but for now we
will let those go for the sake of staying on topic) - note, there are no literal strings
for those that despise them:
</p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">static</span>
            <span class="kwrd">string</span> ToHtmlSelect(<span class="kwrd">this</span> Dictionary&lt;<span class="kwrd">string</span>, <span class="kwrd">string</span>&gt;
listItems, <span class="kwrd">object</span> selectedValue,<br /><span class="kwrd">object</span> attributes)</pre>
          <pre>
            <span class="lnum"> 2: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span> DropDownList htmlSelect = <span class="kwrd">new</span> DropDownList();</pre>
          <pre>
            <span class="lnum"> 4: </span> htmlSelect.Attributes.AddAttributes(attributes);</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span>
            <span class="kwrd">foreach</span> (<span class="kwrd">string</span> key <span class="kwrd">in</span> listItems.Keys)</pre>
          <pre>
            <span class="lnum"> 6: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span> ListItem item = <span class="kwrd">new</span> ListItem(listItems[key],
key);</pre>
          <pre>
            <span class="lnum"> 8: </span> item.Selected = (key.ToLower().Equals(selectedValue.ToString().ToLower()));</pre>
          <pre class="alt">
            <span class="lnum"> 9: </span> htmlSelect.Items.Add(item);</pre>
          <pre>
            <span class="lnum"> 10: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 11: </span>
            <span class="kwrd">return</span> htmlSelect.ToHtml();</pre>
          <pre>
            <span class="lnum"> 12: </span>}</pre>
        </div>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
 
</p>
        <p>
Now, my version does not use the ToAttributeList() extension method hanging off of  <span class="kwrd">object</span> -
mine uses something a bit different, but an extension method nonetheless (although
a bit naive, it will suffice for our purposes):
</p>
        <p>
 
</p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">static</span>
            <span class="kwrd">void</span> AddAttributes(<span class="kwrd">this</span> System.Web.UI.AttributeCollection
attributeCollection,<br /><span class="kwrd">object</span> attributes)</pre>
          <pre>
            <span class="lnum"> 2: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span>
            <span class="kwrd">foreach</span> (PropertyDescriptor
property <span class="kwrd">in</span> TypeDescriptor.GetProperties(attributes))</pre>
          <pre>
            <span class="lnum"> 4: </span> {</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span> attributeCollection.Add(property.Name,
property.GetValue(attributes).ToString());</pre>
          <pre>
            <span class="lnum"> 6: </span> }</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span>}</pre>
        </div>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
 
</p>
        <p>
My extension method hangs instead off of System.Web.UI.AttributeCollection because
my version of the ToHtmlSelect() method works with the System.Web.UI.DropDownList
object, which uses that as the place to store its attributes.
</p>
        <p>
The other key to mine is the following extension method which wraps a technique I
have been using for over 2 years to create HTML (I didn't figure it out on my own,
but can't remember where I saw this exactly - I think in the Google Group for the
AjaxPro.NET component back when it was simply Ajax.NET):
</p>
        <p>
 
</p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>
            <span class="kwrd">public</span>
            <span class="kwrd">static</span>
            <span class="kwrd">string</span> ToHtml(<span class="kwrd">this</span> Control
control)</pre>
          <pre>
            <span class="lnum"> 2: </span>{</pre>
          <pre class="alt">
            <span class="lnum"> 3: </span> StringWriter sw = <span class="kwrd">new</span> StringWriter();</pre>
          <pre>
            <span class="lnum"> 4: </span> HtmlTextWriter htw = <span class="kwrd">new</span> HtmlTextWriter(sw);</pre>
          <pre class="alt">
            <span class="lnum"> 5: </span> control.RenderControl(htw);</pre>
          <pre>
            <span class="lnum"> 6: </span>
            <span class="kwrd">return</span> sw.ToString();</pre>
          <pre class="alt">
            <span class="lnum"> 7: </span>}</pre>
        </div>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
 
</p>
        <p>
Note - this can be used for all sorts of Control-derived ASP.NET HTML wrapper objects
to get you some HTML without string hacking in your layers of code:
</p>
        <p>
 
</p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="lnum"> 1: </span>Calendar c = <span class="kwrd">new</span> Calendar();</pre>
          <pre>
            <span class="lnum"> 2: </span>
            <span class="kwrd">string</span> calendarHtml =
c.ToHtml();</pre>
        </div>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
 
</p>
        <p>
Notice Joe - no literal strings! That should make you happy (I know it makes me happy!).
</p>
        <p>
Now, I love hacking JavaScript as much as the next guy (been doing it hardcore for
the last 2.5 years even with ASP.NET because it is too much fun!), but hacking strings
to create HTML is still not that fun. Even in JavaScript I don't do it if I don't
have to, preferring to use functions that handle that for me (<a title="MochiKit - It makes JavaScript suck less!" href="http://www.mochikit.com/" target="_blank">MochiKit</a> has
some simple DOM functions for handling HTML creation).
</p>
        <p>
Anyway, hope this is of some use to someone out there!
</p>
        <p>
 
</p>
        <div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:b6a24d46-10d0-437a-9c38-7629e4598057" style="margin: 0px; padding: 0px; display: inline;">Technorati
Tags: <a href="http://technorati.com/tags/Extension%20Methods/" rel="tag">Extension
Methods</a> , <a href="http://technorati.com/tags/SubSonic/" rel="tag">SubSonic</a> , <a href="http://technorati.com/tags/ASP.NET/" rel="tag">ASP.NET</a> , <a href="http://technorati.com/tags/C#/" rel="tag">C#</a> , <a href="http://technorati.com/tags/.NET%203.5/" rel="tag">.NET
3.5</a></div>
        <img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=ca16cf2b-c604-4817-ba9c-1b2a1f762327" />
      </body>
      <title>Use ASP.NET Objects, Not Literal HTML Strings</title>
      <guid isPermaLink="false">http://blog.jasonbunting.com/PermaLink,guid,ca16cf2b-c604-4817-ba9c-1b2a1f762327.aspx</guid>
      <link>http://blog.jasonbunting.com/2007/10/31/Use+ASPNET+Objects+Not+Literal+HTML+Strings.aspx</link>
      <pubDate>Wed, 31 Oct 2007 19:38:37 GMT</pubDate>
      <description>&lt;p&gt;
Since learning about &lt;a href="http://www.subsonicproject.com/" target="_blank"&gt;the
SubSonic project&lt;/a&gt; last week, I have spent a bit of time reading up on it, watching
screencasts about it, playing with it, and reading &lt;a href="http://blog.wekeroad.com/" target="_blank"&gt;the
blog of its creator, Rob Conery&lt;/a&gt;. In his post "&lt;a href="http://blog.wekeroad.com/2007/10/25/how-mvc-jquery-and-subsonic-will-make-you-smile/" target="_blank"&gt;How
MVC, jQuery, and SubSonic Will Make You Smile&lt;/a&gt;," Rob talks about the use of .NET
3.5's extension methods, in particular extending a &lt;span style="color: rgb(43, 145, 175);"&gt;Dictionary&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;, &lt;span style="color: rgb(0, 0, 255);"&gt;string&lt;/span&gt;&amp;gt;
to return HTML for a drop down list (HTML select); here is what his version of the
extension method looks like:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ToHtmlSelect(&lt;span class="kwrd"&gt;this&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
listItems, &lt;span class="kwrd"&gt;string&lt;/span&gt; name,&lt;br&gt;
&lt;span class="kwrd"&gt;object&lt;/span&gt; selectedValue, &lt;span class="kwrd"&gt;object&lt;/span&gt; attributes)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; &lt;span class="rem"&gt;// input formats&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; selectFormat
= &lt;span class="str"&gt;"&amp;lt;select name='{0}' id='{0}' {1}&amp;gt;\r\n{2}\r\n &amp;lt;/select&amp;gt;"&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; optionFormat
= &lt;span class="str"&gt;"\t&amp;lt;option value='{0}' {1}&amp;gt;{2}&amp;lt;/option&amp;gt;\r\n"&lt;/span&gt;;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; &lt;span class="rem"&gt;// output&lt;/span&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; StringBuilder sb = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; s &lt;span class="kwrd"&gt;in&lt;/span&gt; listItems.Keys)&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; selectedFlag
= &lt;span class="str"&gt;""&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; text
= listItems[s];&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 14: &lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; =
s;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 15: &lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;value&lt;/span&gt;.ToLower().Equals(selectedValue.ToString().ToLower()))&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 16: &lt;/span&gt; selectedFlag = &lt;span class="str"&gt;"selected=true"&lt;/span&gt;;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 17: &lt;/span&gt; sb.AppendFormat(optionFormat, s.ToString(),
selectedFlag, text);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 18: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 19: &lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; result
= &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(selectFormat, name, attributes.ToAttributeList(),
sb.ToString());&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 20: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; result;&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 21: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt; &lt;pre&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;pre class="code"&gt;&lt;/pre&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
He also mentions that (on line 19) there is another extension method that "hangs off
the object class" which basically enumerates all of the properties of an object, creating
a name/value pair attribute list. He doesn't give the code of that extension method,
which he states "is ScottGu magic at work and something he &lt;a href="http://weblogs.asp.net/scottgu/archive/2007/10/14/asp-net-mvc-framework.aspx" target="_blank"&gt;shows
in his MVC demos&lt;/a&gt;." I have yet to watch those demos myself, but the code is probably
something akin to this:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ToAttributeList(&lt;span class="kwrd"&gt;this&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; attributes) &lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; StringBuilder sb = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (PropertyDescriptor
property &lt;span class="kwrd"&gt;in&lt;/span&gt; TypeDescriptor.GetProperties(attributes)) &lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; sb.AppendFormat(&lt;span class="str"&gt;"{0}='{1}' "&lt;/span&gt;,
property.Name, property.GetValue(attributes).ToString());&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; sb.ToString();&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
This allows you to pass anonymous types, specifying what might normally be optional
parameters, a la something I have been doing in JavaScript for a while using &lt;a title="MochiKit - It makes JavaScript suck less!" href="http://www.mochikit.com/" target="_blank"&gt;MochiKit&lt;/a&gt; (other
JavaScript libs exploit the same literal JavaScript object notation in their function
signatures). The idea is that you don't need to have a structured method signature
that accepts all possible options - you can pass in what you want to specify as a
part of an anonymous object. This will make more sense if you have spent any time
doing this in JavaScript or want to wait a moment and read on.
&lt;/p&gt;
&lt;p&gt;
Anyway, the whole reason I was even posting on this subject is because of a comment
made on Rob's post by one Joe Chung, wherein he states:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;em&gt;"Seeing StringBuilder-generated HTML makes me sad for the future of ASP.NET. Object-oriented
ASP spaghetti code is still spaghetti code."&lt;/em&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
He is referring to the string hacking done in the ToHtmlSelect extension method. I
too don't care for it, and simply wanted to show a nicer way of doing this, which
leverages &lt;strong&gt;objects we already have access to&lt;/strong&gt; in ASP.NET which do that
grunt work for us.
&lt;/p&gt;
&lt;p&gt;
Here is my version of Rob's method (which I still have issues with, but for now we
will let those go for the sake of staying on topic) - note, there are no literal strings
for those that despise them:
&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ToHtmlSelect(&lt;span class="kwrd"&gt;this&lt;/span&gt; Dictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;&amp;gt;
listItems, &lt;span class="kwrd"&gt;object&lt;/span&gt; selectedValue,&lt;br&gt;
&lt;span class="kwrd"&gt;object&lt;/span&gt; attributes)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; DropDownList htmlSelect = &lt;span class="kwrd"&gt;new&lt;/span&gt; DropDownList();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; htmlSelect.Attributes.AddAttributes(attributes);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; key &lt;span class="kwrd"&gt;in&lt;/span&gt; listItems.Keys)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; ListItem item = &lt;span class="kwrd"&gt;new&lt;/span&gt; ListItem(listItems[key],
key);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; item.Selected = (key.ToLower().Equals(selectedValue.ToString().ToLower()));&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; htmlSelect.Items.Add(item);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; htmlSelect.ToHtml();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Now, my version does not use the ToAttributeList() extension method hanging off of&amp;nbsp; &lt;span class="kwrd"&gt;object&lt;/span&gt; -
mine uses something a bit different, but an extension method nonetheless (although
a bit naive, it will suffice for our purposes):
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AddAttributes(&lt;span class="kwrd"&gt;this&lt;/span&gt; System.Web.UI.AttributeCollection
attributeCollection,&lt;br&gt;
&lt;span class="kwrd"&gt;object&lt;/span&gt; attributes)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (PropertyDescriptor
property &lt;span class="kwrd"&gt;in&lt;/span&gt; TypeDescriptor.GetProperties(attributes))&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; {&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; attributeCollection.Add(property.Name,
property.GetValue(attributes).ToString());&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; }&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
My extension method hangs instead off of System.Web.UI.AttributeCollection because
my version of the ToHtmlSelect() method works with the System.Web.UI.DropDownList
object, which uses that as the place to store its attributes.
&lt;/p&gt;
&lt;p&gt;
The other key to mine is the following extension method which wraps a technique I
have been using for over 2 years to create HTML (I didn't figure it out on my own,
but can't remember where I saw this exactly - I think in the Google Group for the
AjaxPro.NET component back when it was simply Ajax.NET):
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ToHtml(&lt;span class="kwrd"&gt;this&lt;/span&gt; Control
control)&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;{&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; StringWriter sw = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringWriter();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; HtmlTextWriter htw = &lt;span class="kwrd"&gt;new&lt;/span&gt; HtmlTextWriter(sw);&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; control.RenderControl(htw);&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; sw.ToString();&lt;/pre&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Note - this can be used for all sorts of Control-derived ASP.NET HTML wrapper objects
to get you some HTML without string hacking in your layers of code:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div class="csharpcode"&gt;
&lt;pre class="alt"&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;Calendar c = &lt;span class="kwrd"&gt;new&lt;/span&gt; Calendar();&lt;/pre&gt;
&lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; calendarHtml =
c.ToHtml();&lt;/pre&gt;
&lt;/div&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Notice Joe - no literal strings! That should make you happy (I know it makes me happy!).
&lt;/p&gt;
&lt;p&gt;
Now, I love hacking JavaScript as much as the next guy (been doing it hardcore for
the last 2.5 years even with ASP.NET because it is too much fun!), but hacking strings
to create HTML is still not that fun. Even in JavaScript I don't do it if I don't
have to, preferring to use functions that handle that for me (&lt;a title="MochiKit - It makes JavaScript suck less!" href="http://www.mochikit.com/" target="_blank"&gt;MochiKit&lt;/a&gt; has
some simple DOM functions for handling HTML creation).
&lt;/p&gt;
&lt;p&gt;
Anyway, hope this is of some use to someone out there!
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:b6a24d46-10d0-437a-9c38-7629e4598057" style="margin: 0px; padding: 0px; display: inline;"&gt;Technorati
Tags: &lt;a href="http://technorati.com/tags/Extension%20Methods/" rel="tag"&gt;Extension
Methods&lt;/a&gt; , &lt;a href="http://technorati.com/tags/SubSonic/" rel="tag"&gt;SubSonic&lt;/a&gt; , &lt;a href="http://technorati.com/tags/ASP.NET/" rel="tag"&gt;ASP.NET&lt;/a&gt; , &lt;a href="http://technorati.com/tags/C#/" rel="tag"&gt;C#&lt;/a&gt; , &lt;a href="http://technorati.com/tags/.NET%203.5/" rel="tag"&gt;.NET
3.5&lt;/a&gt; 
&lt;/div&gt;
&lt;img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=ca16cf2b-c604-4817-ba9c-1b2a1f762327" /&gt;</description>
      <comments>http://blog.jasonbunting.com/CommentView,guid,ca16cf2b-c604-4817-ba9c-1b2a1f762327.aspx</comments>
      <category>ASP.NET</category>
      <category>C#</category>
      <category>Work</category>
    </item>
    <item>
      <trackback:ping>http://blog.jasonbunting.com/Trackback.aspx?guid=d93de0a3-3ed7-4298-85e4-0fd657d8fa09</trackback:ping>
      <pingback:server>http://blog.jasonbunting.com/pingback.aspx</pingback:server>
      <pingback:target>http://blog.jasonbunting.com/PermaLink,guid,d93de0a3-3ed7-4298-85e4-0fd657d8fa09.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://blog.jasonbunting.com/CommentView,guid,d93de0a3-3ed7-4298-85e4-0fd657d8fa09.aspx</wfw:comment>
      <wfw:commentRss>http://blog.jasonbunting.com/SyndicationService.asmx/GetEntryCommentsRss?guid=d93de0a3-3ed7-4298-85e4-0fd657d8fa09</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Say what you will about Microsoft and/or its founder, but you can't deny that Bill
Gates is now doing a lot of good in this world. <a href="http://www.msnbc.msn.com/id/21212128/site/newsweek/" target="_blank">A
recent Q&amp;A</a> with him and <a href="http://www.msnbc.msn.com/id/20920343/site/newsweek/" target="_blank">an
article he wrote</a> both highlight some charitable work being done by the Bill &amp;
Melinda Gates Foundation. 
</p>
        <p>
So, if you don't buy Microsoft products you may be hurting your fellow man. :P
</p>
        <img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=d93de0a3-3ed7-4298-85e4-0fd657d8fa09" />
      </body>
      <title>Bill Gates isn't that evil...</title>
      <guid isPermaLink="false">http://blog.jasonbunting.com/PermaLink,guid,d93de0a3-3ed7-4298-85e4-0fd657d8fa09.aspx</guid>
      <link>http://blog.jasonbunting.com/2007/10/11/Bill+Gates+Isnt+That+Evil.aspx</link>
      <pubDate>Thu, 11 Oct 2007 04:53:56 GMT</pubDate>
      <description>&lt;p&gt;
Say what you will about Microsoft and/or its founder, but you can't deny that Bill
Gates is now doing a lot of good in this world. &lt;a href="http://www.msnbc.msn.com/id/21212128/site/newsweek/" target="_blank"&gt;A
recent Q&amp;amp;A&lt;/a&gt; with him and &lt;a href="http://www.msnbc.msn.com/id/20920343/site/newsweek/" target="_blank"&gt;an
article he wrote&lt;/a&gt; both highlight some charitable work being done by the Bill &amp;amp;
Melinda Gates Foundation. 
&lt;/p&gt;
&lt;p&gt;
So, if you don't buy Microsoft products you may be hurting your fellow man. :P
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.jasonbunting.com/aggbug.ashx?id=d93de0a3-3ed7-4298-85e4-0fd657d8fa09" /&gt;</description>
      <comments>http://blog.jasonbunting.com/CommentView,guid,d93de0a3-3ed7-4298-85e4-0fd657d8fa09.aspx</comments>
    </item>
  </channel>
</rss>