The why, where and how of delegate controls for SharePoint.
KWizCom's VP R&D Shai Peltel gave this presentation during SharePoint Saturday Toronto. Go to: http://kwizcom.blogspot.com/ to download this presentation and a free code example!
31. LimitationOnly targets a pre-defined place holder in the master page Can be overridden by other features with higher priority (lower value) unintentionally
32. Where can I find Delegate Controls? Delegate controls in default.master: AdditionalPageHead (Allows multiple controls!) GlobalSiteLink0, GlobalSiteLink1, GlobalSiteLink2 SmallSearchInputBox TopNavigationDataSource PublishingConsole QuickLaunchDataSource
37. How do I start working with Delegate Controls? Its as easy as 1,2,3! Add a delegate control to your page Create a candidate control Register your candidate to the delegate using a feature!
38. Delegate ControlDeclaration on page / master Registering a new control named “MyTargetedControl” : <SharePoint:DelegateControlrunat="server“ ControlId="MyTargetedControl" Scope="Site Collection" AllowMultipleControls="false"/> Note: The scope attribute indicates where SharePoint will look for possible candidates. It must match the scope of the feature registering the controls Note: Setting the AllowMultipleControls property to true causes all matching candidate controls to be added to the page as children of the delegate control according to the order specified by the Sequence attribute.
39. Delegate ControlRegistration Via feature Registering a user control: <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Control Id="MyTargetedControl" Sequence="90" ControlSrc="~/_ControlTemplates/SayHello.ascx"> <Property Name="ImageSrc">/_layouts/images/gosearch.gif</Property> </Control> </Elements> Registering a custom control: <Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Control Id="MyTargetedControl " Sequence="80" ControlClass= "Company.Product.ControlClass" ControlAssembly= "Company.Product, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXX"> <Property Name="ImageSrc">/_layouts/images/gosearch.gif</Property> </Control> </Elements>
40.
41.
42.
43.
44. More information online Delegate Control description http://msdn.microsoft.com/en-us/library/ms463169.aspx How to: Customize a Delegate Control http://msdn.microsoft.com/en-us/library/ms470880.aspx
Introduction,Hi, My name is X I am Y at KWizCom.As an ISV, the nature of our work is to focus on easy deployment of our solutions at the customer’s end.When we want to extend a feature of SharePoint most of the time our customers just run an installer and our product should fit in their environment with as little customization as possible.This is why we need to take advantage of every possible integration option we can get our hands on.Today we are going to talk about one of the less common of these options – Delegate controls.
If you been around SharePoint long enough, the first thing you did is play with some web parts.They allow you to add web components to your pages in run time, without a need for coding or designing your pages.You can customize them via web part properties, and even add web part connections for more advanced results.Some of the limitation are that everything must be done in a page level.Also – you can only add web parts where you have web part zones, so the page structure cannot be modified – sometimes we want that important capability, if we do not wish our content editors to break our UI design and basic page structure.Speaking of which, content editors can be given edit pages permissions. you cannot control the web parts they can add, their configuration, connections etc.
Advantage: Content editor can choose from limited options thus cannot break the site’s design concept / integrity. Important for WCM public sites.What does “Static templates” mean?if I want to change the content (replace controls/ change properties of controls) I must update the .aspx page.If I want to change the page’s behaviour according to site for example, I will have to deploy different master page/layout per-site or develop a “smart” control that identifies the current site and changes it behaviour accordingly (according to my custom logic: static list of url’s, features, site name etc. – Not ideal)
Change master pages
Change layouts
Another level of page content customization, like web parts, master and layout pages.It is basically a control place holder that allows you to change it’s content based on a feature logic.So you will be able to use the same master page and layout page and still change the page content based on specific logic – feature – without having to code or modify any of these page.
So, going back to our advantages / limitation slide we can see that using a delegate control allows us to support some sort of logic in the controls we want to add, to a specific scope. The control will be registered AND unregistered automatically based on the feature The problem here is that you have to target existing place holder controls – delegate controls – that are already in the page. You can target one of SharePoint’s OOB delegate control or create your own.Say you wish to add a link to your project management system, and you want that link to only appear inside project web sites. You could create a delegate control called “ExternalSystemLink” and create a feature that registers “Link to project Mgmt System” only within project sites.This way, in the future you will be able to do the same withing support sites, sales sites and all based on feature logic instead of hand coding everything into the link control itself.Another issue is that the delegate control usually only loads the highest priority (lowest value) control and another control may override your control without you knowing about it.
Change layouts
Change layouts
Change layouts
Scope – optional. Limit the search for controls in features at the same scope only.Farm, Web Application, Site Collection, Web Site.AllowMultipleControls – optional.
Loading Logic will be separated from the controlsYou can have a generic navigation control, search control that are not aware to your custom loading logicCentralize your loading logic in one place: Feature, or a settings page.