<?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>Buta no Ie &#187; DelegateControl</title>
	<atom:link href="http://singchan.com/tag/delegatecontrol/feed/" rel="self" type="application/rss+xml" />
	<link>http://singchan.com</link>
	<description>The House of Pork and User Experience Development</description>
	<lastBuildDate>Tue, 11 Oct 2011 22:08:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Branding SharePoint 2010 Collaboration Sites &#8211; Part 3 in a Series</title>
		<link>http://singchan.com/2010/02/23/branding-sharepoint-2010-collaboration-sites-part-3-in-a-series/</link>
		<comments>http://singchan.com/2010/02/23/branding-sharepoint-2010-collaboration-sites-part-3-in-a-series/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 16:04:48 +0000</pubDate>
		<dc:creator>Buta</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[HTML/CSS]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[2010]]></category>
		<category><![CDATA[collaboration]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[DelegateControl]]></category>
		<category><![CDATA[master page]]></category>
		<category><![CDATA[SPC09]]></category>
		<category><![CDATA[themes]]></category>
		<category><![CDATA[theming system]]></category>
		<category><![CDATA[ue]]></category>
		<category><![CDATA[user experience]]></category>

		<guid isPermaLink="false">http://singchan.com/?p=181</guid>
		<description><![CDATA[In part two, we posted about how to register our custom style sheets in a way that we could still take advantage of the new SharePoint 2010 colour switching theming engine. In this post we&#8217;ll go through how to do this without having to modify the out-of-the-box master pages or having to use custom master [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://singchan.com/2009/12/29/branding-sharepoint-2010-collaboration-sites-part-2-in-a-series/" title="Branding SharePoint 2010 Collaboration Sites - Part 2 in a Series">part two</a>, we posted about how to register our custom style sheets in a way that we could still take advantage of the new SharePoint 2010 colour switching theming engine. In this post we&#8217;ll go through how to do this without having to modify the out-of-the-box master pages or having to use custom master pages for your sites.</p>
<h3>Delegate Controls</h3>
<p>As I mentioned at the end of part two, the way we&#8217;re going to get our CSS added to our sites and pages is through the use of a <strong>delegate control</strong>. For those of you who aren&#8217;t familiar with delegate controls, they are essentially placeholders for you to inject your own controls via a feature. Your feature can be scoped to either <em>Web</em>, <em>Site</em>, <em>WebApplication</em> or <em>Farm</em>. I&#8217;m going to keep the explanation on delegate controls short as there&#8217;s plenty of information out there about them:</p>
<ul>
<li><a href="http://www.sharepointnutsandbolts.com/2007/06/using-delegate-control.html">Chris O&#8217;Brien: Using the Delegate Control</a></li>
<li><a href="http://www.devx.com/enterprise/Article/36628/1954">SharePoint&#8217;s Delegate Control Power</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.delegatecontrol%28office.14%29.aspx">MSDN 2010 SDK: DelegateControl Class</a></li>
</ul>
<div id="attachment_204" class="wp-caption alignright" style="width: 160px"><a href="http://singchan.com/wordpress/wp-content/uploads/2010/02/AdditionalPageHead.png" rel="lightbox[181]" title="AdditionalPageHead Delegate Control"><img src="http://singchan.com/wordpress/wp-content/uploads/2010/02/AdditionalPageHead-150x150.png" alt="Screenshot of AdditionalPageHead delegate control in v4.master" title="AdditionalPageHead Delegate Control" width="150" height="150" class="size-thumbnail wp-image-204" /></a><p class="wp-caption-text">AdditionalPageHead Delegate Control</p></div>
<h3>The AdditionalPageHead Delegate</h3>
<p>Delegate controls have a <strong>AllowMultipleControls</strong> property which when set to <em>true</em>, all controls keyed to that delegate are added to the page; when set to <em>false</em>, only the control registered with the lowest <em>sequence</em> value is added to the page.</p>
<p>All of the delegate controls in the OOTB master pages have <strong>AllowMultipleControls</strong> set to <em>false</em>, with the exception of one, <strong>AdditionalPageHead</strong>, which does allow multiple controls. And guess what? AdditionalPageHead is actually located in the page head, where you would normally add CSS
<link> elements! This is the perfect place for us to inject any CSS registration controls.</p>
<h3>Putting it all together&#8230;</h3>
<p>Let&#8217;s put together a simple solution using the Visual Studio 2010 SharePoint Tools which will:</p>
<ol>
<li>deploy our CSS file in the <strong>Themable</strong> folder in the <em>/Layouts/1033/Styles</em></li>
<li>deploy a user control into the <em>ControlTemplates</em> folder which uses the <strong>CSSRegistration</strong> control to register our CSS</li>
<li>install a feature which inserts our user control onto our pages via the <strong>AdditionalPageHead</strong> delegate</li>
</ol>
<h4>The CSS</h4>
<p>Keeping it simple, all our CSS does is set the background color of the &lt;body&gt;. We&#8217;ll use #FFF (white) as our default background color and also decorate the rule with one of the SharePoint 2010 compile time directives to whatever we might set the &#8220;Light1&#8243; color value as through the Theme UI.</p>
<pre class="brush: plain; title: ; notranslate">
body {
/*[ReplaceColor(themeColor:&quot;Light1&quot;)]*/
background-color: #fff;
}
</pre>
<h4>The Delegate Control</h4>
<p>Again, nice and simple, we&#8217;re going to use the CSSRegistration control to register our branding CSS after corev4.css:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;%@ Assembly Name=&quot;$SharePoint.Project.AssemblyFullName$&quot; %&gt;
&lt;%@ Register Tagprefix=&quot;SharePoint&quot; Namespace=&quot;Microsoft.SharePoint.WebControls&quot; Assembly=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %&gt;

&lt;sharepoint :CSSRegistration Name=&quot;&lt;% $SPUrl:~sitecollection/_layouts/1033/Styles/Themable/SingChan.SP2010.Branding/branding.css %&gt;&quot; After=&quot;corev4.css&quot; runat=&quot;server&quot; /&gt;
&lt;/sharepoint&gt;
</pre>
<h4>Element Manifest</h4>
<p>And finally we&#8217;ll define our element manifest for our delegate feature:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;elements xmlns=&quot;http://schemas.microsoft.com/sharepoint/&quot;&gt;
    &lt;control Id=&quot;AdditionalPageHead&quot; Sequence=&quot;80&quot; ControlSrc=&quot;~/_ControlTemplates/SingChan.SP2010.Branding/CSSRegistrationControl.ascx&quot; /&gt;
&lt;/elements&gt;
</pre>
<p>You&#8217;ll most likely scope your delegate feature to either <em>Web</em> or <em>Site</em> for branding purposes. I tend to scope my feature at the site collection level to achieve a consistent brand across all the webs in the site collection. If there&#8217;s a requirement to have different branding for one or two specific sites, then we can always have a second feature which deploys those overrides at a web-level scope. If you have vastly different brands across webs in your site collection, then you may want to scope only at the web level so that your brands don&#8217;t conflict or end up with any style inheritance issues.</p>
<h3>That&#8217;s it!</h3>
<p>If all went well, we should see the link to our style sheet emitted after the link to corev4.css!<br />
<div id="attachment_210" class="wp-caption aligncenter" style="width: 160px"><a href="http://singchan.com/wordpress/wp-content/uploads/2010/02/brandingcss.png" rel="lightbox[181]" title="Branding CSS in HTML Source"><img src="http://singchan.com/wordpress/wp-content/uploads/2010/02/brandingcss-150x150.png" alt="Screen shot of HTML source of page containing a link to the branding CSS." title="Branding CSS in HTML Source" width="150" height="150" class="size-thumbnail wp-image-210" /></a><p class="wp-caption-text">Our branding CSS being emitted in HTML</p></div></link>
<p>If all is not well, here&#8217;s the ZIP file containing the branding VS2010 solution for reference:<br />
<a href='http://singchan.com/wordpress/wp-content/uploads/2010/02/SingChan.SP2010.Branding.zip' title="ZIP file containing the branding VS2010 solution">SingChan.SP2010.Branding.zip</a></p>
<h3>Previously&#8230;</h3>
<ul>
<li><a title="Branding SharePoint 2010 Collaboration Sites: Part 1" href="/2009/12/23/branding-sharepoint-2010-collaboration-sites-part-1-in-a-series/">You can find Part One here!</a></li>
<li><a title="Branding SharePoint 2010 Collaboration Sites: Part 2" href="/2009/12/29/branding-sharepoint-2010-collaboration-sites-part-2-in-a-series/">You can find Part Two here!</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://singchan.com/2010/02/23/branding-sharepoint-2010-collaboration-sites-part-3-in-a-series/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

