<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Braindonor Network &#187; ASP.NET</title>
	<atom:link href="http://www.braindonor.net/tag/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.braindonor.net</link>
	<description>Send us your brain...let us do the thinking for you!</description>
	<lastBuildDate>Mon, 30 Jan 2012 20:26:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Visual Studio Fun: Chirpy is Awesome!</title>
		<link>http://www.braindonor.net/coding-blog/visual-studio-fun-chirpy-is-awesome/356/</link>
		<comments>http://www.braindonor.net/coding-blog/visual-studio-fun-chirpy-is-awesome/356/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 17:11:46 +0000</pubDate>
		<dc:creator>John Hoff</dc:creator>
				<category><![CDATA[Coding Blog]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[VisualStudio]]></category>

		<guid isPermaLink="false">http://www.braindonor.net/?p=356</guid>
		<description><![CDATA[Managing the CSS and JavaScript files of a website can be an extremely frustrating, but rewarding experience. I've been introducing tools at work to help manage this experience such as SASS, LESS, CoffeeScript, etc, with mixed results. By themselves, each of these tools do a great job, but how to I leverage their power together? [...]]]></description>
			<content:encoded><![CDATA[<p>Managing the CSS and JavaScript files of a website can be an extremely frustrating, but rewarding experience.  I've been introducing tools at work to help manage this experience such as SASS, LESS, CoffeeScript, etc, with mixed results.  By themselves, each of these tools do a great job, but how to I leverage their power together?  Having fifteen JS and CSS includes in a site is still extremely inefficient.  <a href="http://chirpy.codeplex.com/" target="_blank">Chirpy</a> is a tool that helps to bring all of this together in one plugin in Visual Studio...but I see a lot of people completely missing the most powerful feature of Chirpy: <a href="http://www.weirdlover.com/2010/07/18/chirpy-attains-godlike-abilities-in-version-1-0-0-4/#mash">FileGroups</a>.</p><span id="more-356"></span>

<p>This CSS and JS on my blog is admittedly inefficient.  I'm here to write about code, not spend all my time coding so that I can write about code.  However, it is a great example of how NOT to keep your JavaScript and CSS files organized: 10 individual CSS requests and 15 individual JavaScript requests.  If all of the JavaScript files were being called at just before the end of the body tag and if all of the CSS files are part of the same media type they can be combined into a single file.  I try to follow the <a href="http://developer.yahoo.com/yslow/" target="_blank">YSlow</a> conventions where possible.</p>

<img src="http://www.braindonor.net/wp-content/uploads/2012/01/chirpy_bundle.png" alt="" title="chirpy_bundle" width="358" height="538" class="alignright size-full wp-image-357" />

<p>Chirpy allows for this to be done in a Visual Studio project at build time.  If you have already gone through the tutorial and are starting to work through adding your own chirp files into Visual Studio.  You need to start maching files together with Chirpy using *.chirp.config files.  I've included a quick screenshot that I am using on a project to illustrate how I've organized things.  This is an ASP.NET MVC3 project.  I have included folders for css and javscript inside ~/Content/.  The Bundle.chirp.config file is pulling everything from there and generating five virtual files...and that is all of the content required for the entire site!</p>

<p>I have to mention that the ~/Scripts folder has been left alone as that is where the conventions dictate that JavaScript files should go. I break this convention and say that only <i>Library</i> JavaScript files that are provided by NuGet reside. In my projects, NuGet loads script files into ~/Scripts/, I load script files into ~/Content/js/.  I also have to note that my less files are <i>not</i> *.chirp.less files.  As we are using the FileGroup to  bundle everything together, Chirpy will parse those files when it compiles the group! You can also mix-and-match CSS, LESS and SESS files to your hearts content.</p>

<p>So what does my Bundle.chirp.config look like?</p>
<pre class="brush: plain">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;root xmlns=&quot;urn:ChirpyConfig&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation=&quot;urn:ChirpyConfig http://www.weirdlover.com/chirpy/chirp.xsd&quot;&gt;
    &lt;FileGroup Name=&quot;style.css&quot;&gt;
        &lt;File Path=&quot;css/fontface.less&quot; /&gt;
        &lt;File Path=&quot;css/reset.less&quot; /&gt;
        &lt;File Path=&quot;css/base.less&quot; /&gt;
        &lt;File Path=&quot;css/fonts.less&quot; /&gt;
        &lt;File Path=&quot;css/mixins.less&quot; Minify=&quot;false&quot; /&gt;
        &lt;File Path=&quot;css/layout.less&quot; Minify=&quot;false&quot; /&gt;
        &lt;File Path=&quot;css/homepage.less&quot; Minify=&quot;false&quot; /&gt;
        &lt;File Path=&quot;css/registration.less&quot; Minify=&quot;false&quot; /&gt;
    &lt;/FileGroup&gt;
    &lt;FileGroup Name=&quot;ie.css&quot;&gt;
        &lt;File Path=&quot;css/ie.less&quot; /&gt;
    &lt;/FileGroup&gt;
    &lt;FileGroup Name=&quot;script.js&quot;&gt;
        &lt;File Path=&quot;../Scripts/jquery-1.5.1.min.js&quot; Minify=&quot;false&quot; /&gt;
        &lt;File Path=&quot;js/ui.js&quot; Minify=&quot;false&quot; /&gt;
    &lt;/FileGroup&gt;--&gt;
    &lt;FileGroup Name=&quot;ielt9.js&quot;&gt;
        &lt;File Path=&quot;js/html5.js&quot; Minify=&quot;false&quot; /&gt;
    &lt;/FileGroup&gt;
    &lt;FileGroup Name=&quot;ie.js&quot;&gt;
        &lt;File Path=&quot;js/PIE.js&quot; Minify=&quot;false&quot; /&gt;
        &lt;File Path=&quot;js/selectivizr-min.js&quot; Minify=&quot;false&quot; /&gt;
    &lt;/FileGroup&gt;
&lt;/root&gt;</pre>

<p>Now i have the 5 files that I am ready to include.  Why 5 files?  I need to support IE 7,8,9.  The labels on the bundle give some hints to the logic, but looking at the HTML in the template should clear it all up.</p>

<p>Header HTML:</p>
<pre class="brush: plain">    &lt;link rel=&quot;stylesheet&quot; media=&quot;all&quot; href=&quot;/Content/style.css&quot; /&gt;
    &lt;!--[if lt IE 9]&gt;
        &lt;script src=&quot;/content/ielt9.js&quot;&gt;&lt;/script&gt;
    &lt;![endif]--&gt;
    &lt;!--[if lte IE 9]&gt;
        &lt;link rel=&quot;stylesheet&quot; media=&quot;all&quot; href=&quot;/Content/ie.min.css&quot; /&gt;
    &lt;![endif]--&gt;
&lt;/head&gt;</pre>

<p>Footer HTML:</p>
<pre class="brush: plain">    &lt;script src=&quot;/Content/script.js&quot;&gt;&lt;/script&gt;
    &lt;!--[if lte IE 9]&gt;
        &lt;script type=&quot;/Content/ie.js&quot;&gt;&lt;/script&gt;
    &lt;![endif]--&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>

<p>Now I have 13 files being reduced to 5.  I'm confident that I will be adding more files as I complete the project&#8212;and I am even more confident that 5 files are all that I will be including in my HTML pages.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.braindonor.net/coding-blog/visual-studio-fun-chirpy-is-awesome/356/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery and ASP UpdatePanel Integration</title>
		<link>http://www.braindonor.net/coding-blog/jquery-and-asp-updatepanel-integration/328/</link>
		<comments>http://www.braindonor.net/coding-blog/jquery-and-asp-updatepanel-integration/328/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 17:42:10 +0000</pubDate>
		<dc:creator>John Hoff</dc:creator>
				<category><![CDATA[Coding Blog]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.braindonor.net/?p=328</guid>
		<description><![CDATA[With my latest gig sending me back into the .NET world, I have been busy migrating quite a few of my tools and experience to play nice with ASP.NET sites. One of my favorite open-source tools that is gaining popularity in .NET is jQuery. For several years now, I have been using jQuery heavily to [...]]]></description>
			<content:encoded><![CDATA[<p>With my latest gig sending me back into the .NET world, I have been busy migrating quite a few of my tools and experience to play nice with ASP.NET sites. One of my favorite open-source tools that is gaining popularity in .NET is <a href="http://jquery.com/" target="_blank">jQuery</a>. For several years now, I have been using jQuery heavily to provide rich interaction on websites. When faced with the basic UpdatePanel in ASP.NET, I was presented with a challenge. I wanted a solution that would automatically call jQuery so that new content was properly parsed and updated.<span id="more-328"></span> Because I had been managing all the AJAX calls in my other development, this was trivially easy to do. UpdatePanel hides all of this inside the ASP AJAX libraries and scripts—making it difficult to figure out where and how to structure my jQuery code. After some research and experimentation, I have a solution up and running on multiple sites now that integrates everything in a very clean manner.</p>

<p><strong>Scoping jQuery Rewrites</strong><br />
The first step is to scope all of the jQuery rewrites. The typical method of integrating jQuery rewrites into a website is to add a document.ready function like so:</p>

<pre class="brush: js">$(document).ready(function() {
    $('.content_tab_button').click(function(){
        $('.content_tab_container').load('/newcontent.html');
    });
});</pre>

<p>Because the rewrites are only called when the document.ready event fires, integrating with new content pulled in from AJAX needs to be done differently. By placing our rewrites in a new function that recieves the scope being updated, we can have a single initialization handle all of the updating:</p>

<pre class="brush: js">function my_initializer(data){
    data.find('.content_tab_button').click(function(){
        $('.content_tab_container').load('/newcontent.html');
        my_initializer($('.content_tab_container').html());
    });
}
$(document).ready(function() {
    my_initializer($(document));
});</pre>

<p>Everything is now scoped cleanly. The rewrites are applied to the document when the page is loaded, and the new content when the tab button is clicked. Even if you are not an ASP.NET developer, please take the above scoping strategy with you!</p>

<p><strong>How The UpdatePanel Works</strong><br />
At the highest level, an UpdatePanel refreshes its entire contents when a specificied event occurs within the panel. Server-side, the event triggering the refresh is processed, and the entire page-stae is regenerated. Then, only the content inside the UpdatePanel is pushed out. This is important for any developer using UpdatePanel to understand: UpdatePanel is much more convenient than it is efficient. As a result, our solution must follow that model.</p>

<p>With that in mind, we look to javascript class that is already managing the UpdatePanel, the <a href="http://msdn.microsoft.com/en-us/library/bb311028.aspx" target="_blank">Sys.WebForms.PageRequestManager</a> class. In this class, we see an event handler for the <a href="http://msdn.microsoft.com/en-us/library/bb397523.aspx" target="_blank">pageLoad event</a>. In the documentation, you can see that we are able to fetch the update panels that were just updated. In the example, they are looking for a panel with a specific ID. In our case, we are looking at having our rewrites applied to any panel that was updated:</p>

<pre class="brush: js">var panels = args.get_panelsUpdated();
if (panels.length &gt; 0) {
    for (i = 0; i &lt; panels.length; i++) {
        my_initializer($(panels[i]));
    }
}</pre>

<p>Because we have already scoped our jQuery code, this will work like a charm.</p>

<p><strong>Putting It All Together</strong><br />
We can put all of the code together now, and we'll have a script that will play cleanly with the UpdatePanel:</p>

<pre class="brush: js">function my_initializer(data){
    data.find('.content_tab_button').click(function(){
        $('.content_tab_container').load('/newcontent.html');
        my_initializer($('.content_tab_container').html());
    });
}
function my_pageloaded_initializer(sender, args) {
    var panels = args.get_panelsUpdated();
    if (panels.length &gt; 0) {
        for (i = 0; i &lt; panels.length; i++) {
            my_initializer($(panels[i]));
        }
    }
}
$(document).ready(function() {
    my_initializer($(document));
    Sys.WebForms.PageRequestManager.getInstance()
        .add_pageLoaded(my_pageloaded_initializer);
});</pre>

<p>All of our rewrites are called once—and only once—during page load and UpdatePanel refresh. Enjoy!</p>]]></content:encoded>
			<wfw:commentRss>http://www.braindonor.net/coding-blog/jquery-and-asp-updatepanel-integration/328/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

