<?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>Earnest Apathy &#187; ASP.Net</title>
	<atom:link href="http://blog.pyrolupus.com/category/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pyrolupus.com</link>
	<description>The meaning of one life</description>
	<lastBuildDate>Wed, 29 Jun 2011 17:33:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Multiple jQueryUI Themerolled Themes inside ASP.Net App_Themes</title>
		<link>http://blog.pyrolupus.com/2009/03/multiple-jqueryui-themerolled-themes-inside-aspnet-app_themes/</link>
		<comments>http://blog.pyrolupus.com/2009/03/multiple-jqueryui-themerolled-themes-inside-aspnet-app_themes/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 22:49:48 +0000</pubDate>
		<dc:creator>pyrolupus</dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[jQueryUI]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[themes]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://blog.pyrolupus.com/?p=106</guid>
		<description><![CDATA[One of the things I love about jQueryUI is the fact that it can generate a download based upon one of several great-looking themes. This rolls up all the images and CSS into a single zip along with a customized &#8230; <a href="http://blog.pyrolupus.com/2009/03/multiple-jqueryui-themerolled-themes-inside-aspnet-app_themes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the things I love about <a href="http://jqueryui.com/">jQueryUI</a> is the fact that it can generate a download based upon one of several <a title="jQueryUI ThemeRoller" href="http://jqueryui.com/themeroller/">great-looking themes</a>.  This rolls up all the images and CSS into a single zip along with a customized JavaScript file.  This is awesome, but what happens if I want to grab multiple themes, drop them into an ASP.Net website, and be able to switch between them?<br />
<span id="more-106"></span><br />
After downloading a couple of themes and renaming the unzipped directories, we can see that there are several things included in our zip:</p>
<p><img class="size-full wp-image-107 alignnone" title="jQueryUI Theme Directories" src="http://blog.pyrolupus.com/wp-content/uploads/2009/03/uitheme_dirs.png" alt="jQueryUI Theme Directories" width="197" height="223" /></p>
<p><img class="size-full wp-image-108 alignright" title="App_Theme Directories" src="http://blog.pyrolupus.com/wp-content/uploads/2009/03/apptheme_dirs.png" alt="App_Theme Directories" width="131" height="113" align="right" />The aforementioned CSS and images are inside that <code>/css</code> directory, plus some other goodies, like example code for using each of UI&#8217;s widgets. When I want to use a jQueryUI theme in an ASP.Net, I just copy the <code>theme-name</code> subdirectory from <code>/css</code> into the App_Themes .Net solution folder.  From there, it&#8217;s a simple matter of letting the web app know to use the one of the themes in Web.config:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pages</span> <span style="color: #000066;">styleSheetTheme</span>=<span style="color: #ff0000;">&quot;start&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>I used <a href="http://weblogs.asp.net/vimodi/articles/WhatIs_StyleSheetTheme.aspx">StyleSheetTheme over Theme</a>, because a) StyleSheetTheme is processed earlier in the page lifecycle&#8211;before page control properties applied&#8211;and b) since these are style-only themes (meaning no .Net-specific .skin files that contain server-processed control properties), StyleSheetTheme just makes more sense.</p>
<p>Now that I have a couple of Themerolled themes, how the heck do I get the right customized JavaScript file to load?  Glad you (er, I) asked!</p>
<p>When you download a themerolled theme, the included JavaScript file is named <code>jquery-ui-1.7.1.custom.min.js</code> (with the appropriate version number if you are reading this a while after I write it).  The first thing I do is change that &#8220;custom&#8221; into the name of the theme:  <code>jquery-ui-1.7.1.south-street.min.js</code> &#8212; and drop it into my site&#8217;s <code>/js</code> directory..  Now it&#8217;s time to crack open my Master page&#8217;s code-behind:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> MasterPage 
 <span style="color: #008000;">:</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">MasterPage</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Page_Init<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">//prefer StyleSheetTheme, but use Theme if</span>
    <span style="color: #008080; font-style: italic;">//  no StyleSheetTheme is present</span>
    <span style="color: #6666cc; font-weight: bold;">string</span> themeName <span style="color: #008000;">=</span> Page<span style="color: #008000;">.</span><span style="color: #0000FF;">StyleSheetTheme</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span> 
     <span style="color: #008000;">?</span> Page<span style="color: #008000;">.</span><span style="color: #0000FF;">StyleSheetTheme</span> 
     <span style="color: #008000;">:</span> Page<span style="color: #008000;">.</span><span style="color: #0000FF;">Theme</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #6666cc; font-weight: bold;">string</span> uiScriptPath <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span>
     <span style="color: #666666;">&quot;~/js/jquery-ui-1.7.1.{0}.min&quot;</span>, 
     themeName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    ScriptManager1<span style="color: #008000;">.</span><span style="color: #0000FF;">Scripts</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>
     <span style="color: #008000;">new</span> ScriptReference<span style="color: #008000;">&#40;</span>uiScriptPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Not using ASP.Net AJAX?  Then replace that last statement with:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Page<span style="color: #008000;">.</span><span style="color: #0000FF;">ClientScript</span><span style="color: #008000;">.</span><span style="color: #0000FF;">RegisterClientScriptInclude</span><span style="color: #008000;">&#40;</span>
 <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetType</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, <span style="color: #666666;">&quot;jqueryui&quot;</span>, uiScriptPath<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Now, if you want to provide a way for users of your site to switch between themes, the right customized jQueryUI file gets picked up!</p>
<p>On a related note, the <a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=103654">MasterPage class has no PreInit event</a>, so we cannot <b>globally</b> (<i>i.e.</i>, just one time) do the following:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">//no such thing as a MasterPage.PreInit event :-(</span>
<span style="color: #008080; font-style: italic;">//  so, only works on content, i.e., aspx pages</span>
<span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Page_PreInit<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">//grab from profile or session or cookie, etc.</span>
  Page<span style="color: #008000;">.</span><span style="color: #0000FF;">StyleSheetTheme</span> <span style="color: #008000;">=</span> Profile<span style="color: #008000;">.</span><span style="color: #0000FF;">Theme</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>So how can we easily pick up our JavaScript file across the whole site if I want users to be able to switch between themes?  (Microsoft suggested doing so in Global.asax in the above linked suggestion&#8230;but how the blazes can you access the Page.(StyleSheet)Theme inside Global.asax?!)</p>
<p>It just so happens that <a href="http://www.edream.org/">Sue Googe</a> <a href="http://www.edream.org/BlogArticle.aspx?RecordID=103">blogged about solving that very problem</a> and also <a href="http://www.codeproject.com/KB/aspnet/dynamicThemes.aspx">posted her solution to CodeProject</a>.  In brief, she created a <code>BasePage</code> class (which inherits from <code>Page</code>) in the <code>/App_Code</code> folder that sets the theme, and then all your site pages inherit from <code>BasePage</code>.  Less than ideal for a pre-existing site with many pages, but I have yet to find or come up with a better globally-available solution.  (Thanks, Sue! ^_^)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pyrolupus.com/2009/03/multiple-jqueryui-themerolled-themes-inside-aspnet-app_themes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

