<?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>All1 Source technologies &#187; Event</title>
	<atom:link href="http://www.all1sourcetech.com/tag/event/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.all1sourcetech.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 23 Nov 2011 12:26:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Dynamically Setting the Theme</title>
		<link>http://www.all1sourcetech.com/dynamically-setting-theme/</link>
		<comments>http://www.all1sourcetech.com/dynamically-setting-theme/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 05:40:11 +0000</pubDate>
		<dc:creator>Suzanne</dc:creator>
				<category><![CDATA[Microsoft Technology]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CSS files.]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[IHttpModule]]></category>
		<category><![CDATA[Load()]]></category>
		<category><![CDATA[Master pages]]></category>
		<category><![CDATA[PreInit()]]></category>
		<category><![CDATA[web.config]]></category>
		<category><![CDATA[Website]]></category>

		<guid isPermaLink="false">http://www.all1sourcetech.com/?p=1036</guid>
		<description><![CDATA[Themes can be used to customize the look of your Website. If you need to select the theme based on user settings, you’ll be glad to know that ASP.NET allows you to set the theme of a page dynamically when the page is being created. This process is pretty straight forward; however, there are a [...]]]></description>
			<content:encoded><![CDATA[<p>Themes can be used to customize the look of your<a href="http://www.all1Press.com" target="_blank"> Website</a>. If you need to select the theme based on user settings, you’ll be glad to know that<a title="ASP.NET" href="http://www.all1Press.com" target="_blank"> ASP.NET </a>allows you to set the theme of a page dynamically when the page is being created. This process is pretty straight forward; however, there are a couple of issues that may arise.</p>
<p>First of all, ASP.NET establishes the current<a title="theme" href="http://www.all1Press.com" target="_blank"> theme</a> prior to the page’s Load() event. <strong><span style="color: #993366;">In order to dynamically change the theme before the Load() event, you&#8217;ll need to set it during the page’s PreInit() event.</span></strong></p>
<p><strong>Setting the Theme in the PreInit() Event</strong></p>
<p>That was easy enough. But what happens if your site uses a master page?<a title="Master pages" href="http://www.all1Press.com" target="_blank"> Master pages </a>allow you to control the appearance of all the pages on your site from a single master page. So it makes sense to want to set the theme from the master page. However, master pages do not provide a PreInit() event. So setting the theme dynamically from a master page is not as easy as you might guess.</p>
<p><strong><span style="color: #993366;">One way to deal with this is to create a class that derives from<a href="http://www.all1Press.com" target="_blank"> IHttpModule. </a>This class can be made to respond to all page requests on your site, and it gets called just before the request is handled, in plenty of time to set the theme for the current page.</span></strong></p>
<pre>public class ThemeManager : IHttpModule</pre>
<pre>{
   public ThemeManager()</pre>
<pre>    {</pre>
<pre>    }</pre>
<pre>  public void Init(HttpApplication app)</pre>
<pre>    {</pre>
<pre>        // Set our handler to be called just before handling a request</pre>
<pre>        app.PreRequestHandlerExecute +=</pre>
<pre>            new EventHandler(Context_PreRequestHandlerExecute);</pre>
<pre>    }</pre>
<pre>  void Context_PreRequestHandlerExecute(object sender, EventArgs e)</pre>
<pre>    {</pre>
<pre>        // Note: If handler does not implement IRequiresSessionState or</pre>
<pre>        // IReadOnlySessionState then Session state will be unavailable</pre>
<pre>        if (HttpContext.Current.CurrentHandler is Page)</pre>
<pre>        {</pre>
<pre>            // Set theme</pre>
<pre>            Page page = (Page)HttpContext.Current.CurrentHandler;</pre>
<pre>            page.Theme = "MyTheme";</pre>
<pre>        }</pre>
<pre>        public void Dispose()</pre>
<pre>        {</pre>
<pre>        }</pre>
<pre>    }</pre>
<pre>}</pre>
<p><strong>Setting the Theme from an IHttpModule-Derived Class</strong></p>
<p>In order to use this class, you’ll have to modify your web.config file.</p>
<pre>&lt;configuration&gt;</pre>
<pre> &lt;system.web&gt;</pre>
<pre> &lt;httpModules&gt;</pre>
<pre> &lt;add /&gt;</pre>
<pre> &lt;/httpModules&gt;</pre>
<pre> &lt;/system.web&gt;</pre>
<pre>&lt;/configuration&gt;</pre>
<p><strong>Web.config Changes</strong></p>
<p>Also, be sure to clear any theme settings from your<a href="http://www.all1Press.com" target="_blank"> web.config file. </a>Otherwise, it’s possible for ASP.NET to get confused and possibly reference multiple CSS files.</p>
<p>ASP.NET themes are quite powerful, and can be used to manage the appearance of various controls and images. Another thing themes do is let you specify CSS, or style sheets. If this is all your themes are used for, then a much simpler approach can be taken.</p>
<p>All you need to do is add a Literal control inside of the &lt;head&gt; section of your master page. Then, you can set it to include your style sheet during the master page&#8217;s Load event.</p>
<p>Since you aren&#8217;t modifying the look of controls using skins, there is no need to change this setting in the PreInit() handler. In fact, you could handle it even later than the Load event since all that needs to happen is your page references the correct<a href="http://www.all1Press.com" target="_blank"> CSS file.</a></p>
<input id="gwProxy" type="hidden" />
<input id="jsProxy" onclick="jsCall();" type="hidden" />
<p><a href="http://www.all1tunes.com" target="_blank">http://www.all1tunes.com</a></p>
<p><a href="http://www.all1social.com" target="_blank">http://www.all1social.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.all1sourcetech.com/dynamically-setting-theme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

