Delegate Controls: What, Where and How

2,360 views

Published on

This presentation introduces delegate controls to develoepers, shows how to use them and when in SharePoint 2007 and 2010.
Code example is embedded in the file so downlaod to get it.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,360
On SlideShare
0
From Embeds
0
Number of Embeds
83
Actions
Shares
0
Downloads
22
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • Introduction,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.
  • 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.
  • Delegate Controls: What, Where and How

    1. 1. Shai Petel<br />MCTS, MCT<br />VP R&D – KWizCom<br />shai@kwizcom.com<br />Delegate Controls - What, Where & How<br />
    2. 2. Topics<br /><ul><li>Review different SharePoint pages customization options
    3. 3. What’s a “Delegate Control”?
    4. 4. Why should I use it?
    5. 5. Where can I find them?
    6. 6. How do I start working with Delegate Controls?</li></li></ul><li>Customize SharePoint pagesWeb parts<br />SharePoint 101… Add web parts<br /><ul><li>Advantages
    7. 7. Done in run-time by non-technical content manager
    8. 8. Flexible and customizable by user via web part properties
    9. 9. Limitation</li></ul>Per-page operation (add, modify, remove)<br />Cannot change page structure, only add/remove web parts<br />Cannot moderate options (allow/deny only)<br />
    10. 10. Customize SharePoint pagesWeb parts<br />
    11. 11. Customize SharePoint pagesMaster / Layout Pages<br />Master pages, Page Layouts<br /><ul><li>Advantages
    12. 12. Easily define pages design structure (and base content)
    13. 13. Provide templates which enables easy switching
    14. 14. Limit choices to several approved predefined option
    15. 15. Limitation</li></ul>Static set of templates<br />Cannot target content based on logic, need to manually develop logic or create several master / layout pages<br />
    16. 16. Customize SharePoint pagesMaster / Layout Pages<br />
    17. 17. Customize SharePoint pagesMaster / Layout Pages<br />
    18. 18. What is a Delegate Control<br />A Delegate Control is:<br /><ul><li>Another level of encapsulation
    19. 19. Control “place holder”
    20. 20. Enables run-time binding between a page and actual hosted controls
    21. 21. Built in support for logic – loading based on features
    22. 22. Enables making changes in your provisioned sites without having to recode your site pages!</li></li></ul><li>Why use Delegate Controls?<br />Delegate Controls<br /><ul><li>Advantages
    23. 23. Support logic for loading controls
    24. 24. Automatic deploy to specific scope (Farm, Web Application, Site Collection, Web Site)
    25. 25. Control will unregister once it’s feature is deactivated
    26. 26. Limitation</li></ul>Only targets a pre-defined place holder in the page<br />Can be overridden by other features with higher priority (lower value) unintentionally*<br />
    27. 27. Where can I find Delegate Controls?<br />Delegate controls in default.master: <br />AdditionalPageHead (Allows multiple controls!)<br />GlobalSiteLink0, GlobalSiteLink1, GlobalSiteLink2 <br />SmallSearchInputBox<br />TopNavigationDataSource<br />PublishingConsole<br />QuickLaunchDataSource<br />
    28. 28. Delegate Controls in Features<br />
    29. 29. Examples of build in controlsCustom logic!<br />
    30. 30. Examples of build in controlsCustom logic!<br />
    31. 31. Examples of build in controlsFeature logic!<br />
    32. 32. How do I start working with Delegate Controls?<br />Its as easy as 1,2,3!<br />Add a delegate control to your page<br />Create a candidate control<br />Register your candidate to the delegate using a feature!<br />
    33. 33. Delegate ControlDeclaration on page / master<br />Registering a new delegate control named “MyTargetedControl” :<br /><SharePoint:DelegateControlrunat="server“ ControlId="MyTargetedControl" Scope="Site Collection" AllowMultipleControls="false"/><br />Note: The scope attribute indicates where SharePoint will look for possible candidates. If specified, it must match the scope of the feature registering the controls<br />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.<br />
    34. 34. Delegate ControlRegistration Via feature<br />Registering a user control:<br /><Elements xmlns="http://schemas.microsoft.com/sharepoint/"><br /> <Control Id="MyTargetedControl" Sequence="90" ControlSrc="~/_ControlTemplates/SayHello.ascx"><br /> <Property Name="ImageSrc">/_layouts/images/gosearch.gif</Property><br /> </Control><br /></Elements><br />Registering a custom control:<br /><Elements xmlns="http://schemas.microsoft.com/sharepoint/"><br /> <Control Id="MyTargetedControl " Sequence="80"<br />ControlClass= "Company.Product.ControlClass" ControlAssembly= "Company.Product, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXX"><br /> <Property Name="ImageSrc">/_layouts/images/gosearch.gif</Property><br /> </Control><br /></Elements> <br />
    35. 35. So, Why should I use it?<br />Now you can:<br /><ul><li>Easily override existing SharePoint controls without any need to update provisioned sites/pages!
    36. 36. Implement a master page that behaves differently in different sites, based on features.</li></li></ul><li>So, Why should I use it?<br />Usage examples:<br /><ul><li>Register CSS or JS file to all pages within scope
    37. 37. Add SEO page header tags
    38. 38. Replace SharePoint search box
    39. 39. Change top/context navigation data source based on some other logic (while using the same shared master page)</li></li></ul><li>Questions<br />Questions before live demo?<br />
    40. 40. Hands-on examples<br />Live demo:<br /><ul><li> Feature that registers delegate control
    41. 41. Activating / Deactivating</li></li></ul><li>New in 2010<br />In SharePoint 2010 – Injecting JS files can be done directly form your feature!<br />
    42. 42. It all comes together...<br />
    43. 43. More information online<br />Delegate Control description http://msdn.microsoft.com/en-us/library/ms463169.aspx<br />How to: Customize a Delegate Control http://msdn.microsoft.com/en-us/library/ms470880.aspx<br />
    44. 44. Questions<br />

    ×