Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

SharePoint's Delegate Control Power : Page 2

Learn about a handy feature that lets you isolate the functionality of one control from another on one or more Web sites.


advertisement
Declarations in Sequence
When you create a delegate control in a feature part of a page, the declaration is a sequence number. The lower the sequence number attached to a control, the better the chance that the control will be used to replace the associated delegate control, and the best control is defined as the control that has the lowest sequence number. When SharePoint selects the control to replace the delegate control, it looks through the list of activated controls and selects the best control or controls. If the delegate control is set to not allow multiple controls—such as in a page header, for instance—then it selects the control defined with the lowest sequence number.

For instance, take a look at this delegate control definition from the OSearchBasicFeature, which comes with MOSS:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Control Id="SmallSearchInputBox" Sequence="50" ControlClass= "Microsoft.SharePoint.Portal.WebControls.SearchBoxEx" ControlAssembly= "Microsoft.SharePoint.Portal, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"> <Property Name="GoImageUrl">/_layouts/images/gosearch.gif</Property> <Property Name="GoImageUrlRTL">/_layouts/images/goRTL.gif</Property> <Property Name="GoImageActiveUrl"> /_layouts/images/gosearch.gif</Property> <Property Name="GoImageActiveUrlRTL"> /_layouts/images/goRTL.gif</Property> <Property Name="DropDownMode">ShowDD</Property> <Property Name="SearchResultPageURL"> /_layouts/osssearchresults.aspx</Property> <Property Name="ScopeDisplayGroupName" /> <Property Name="FrameType">None</Property> </Control> </Elements>

In this definition the control is given a name: the name that must match the name used on the master page, in the page layout, or on the page. Delegate controls can either be web controls, as specified in the preceding example, or user controls. If you're specifying a user control, use a Url attribute in the control instead of the ControlClass and ControlAssembly attributes.



The preceding XML example demonstrates how to define the delegate control for SharePoint; however, it doesn't put the control on the page, which is the responsibility of the <SharePoint:DelegateControl> control reference for the page.

Placing the Delegate Control
If you crack open default.master in WSS you'll find a delegate control with a ControlId attribute: SmallSearchInputBox It matches the Id attribute of the previous Control tag:

<asp:ContentPlaceHolder id="PlaceHolderSearchArea" runat="server"> <SharePoint:DelegateControl runat="server" ControlId= "SmallSearchInputBox" /> </asp:ContentPlaceHolder>

This tag places the delegate control inside of a master page's placeholder, which means you can use delegate controls to override the search control by not specifying the placeholder in the ASPX file as well as by creating and activating a new feature with a lower sequence number control on the site. In other words, there are many ways to customize the output: one way that requires a completely new page and another way that can be controlled by features.

Why would you have both? One sample case might be for a search control on an ecommerce site, where the pages typically have the same look and feel throughout the site except for the page that displays the checkout process. Generally, although checkout pages have the same basic appearance as the other pages on the site, they will appear different, usually by virtue of having fewer distractions. The idea, naturally, is a design that encourages users to complete the purchase without being unduly distracted. For instance, as the user is checking out it might be appropriate to suppress the availability of the search box even if the site is embellished with enhanced search features.

Another place where you can find a delegate control on the master page is for additional page headers. This control is from the WSS default.master file:

<SharePoint:DelegateControl runat="server" ControlId= "AdditionalPageHead" AllowMultipleControls="true"/>

This delegate control is set to allow multiple controls, which also might be useful for an ecommerce site where you want the page header to add keywords dynamically. You can build a control that emits metatags to add to the header. For instance, you might create a control that emits keywords based on where the user is in the navigation. It might also emit other metatags that allow the site's internal search engine to do a better job of indexing the site.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap