How to: Customize the Variations Label Control Logic

This functionality becomes obsolete in Microsoft SharePoint Server 2010.

Each of the default master pages that are available in Microsoft Office SharePoint Server 2007 for publishing sites—such as Default.Master, LeftNavFlyouts.Master, Stacked.Master, and TopNavFlyouts.Master—contain a reference to a file called VariationsLabelMenu.ascx through a DelegateControl element in their markup, as shown here.

<SharePoint:DelegateControl  ControlId="VariationsFlagControl" />

The VariationsLabelMenu.ascx file contains the logic to render variation labels on a page. The variation label control is a user control on a variation page. It displays the corresponding variation pages that are available for that page so that the user can quickly navigate to the other available variations of the page.

The VariationsLabelMenu.ascx file is defined in the path \<Program Files>\Common Files\Microsoft Shared Debug\Web Server Extensions\12\Template\ControlTemplates. The publishing feature in Office SharePoint Server 2007 registers the DelegateControl element in \<Program Files>\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES\Publishing\VariationsFlagControl.xml. This XML file points to the VariationsLabelMenu.ascx file, which causes all sites provisioned with the "Corporate Intranet" site template to have the rendering provided by VariationsLabelMenu.ascx. This also causes the Default.Master master page for all site collections in the server farm to contain the same rendering provided by VariationsLabelMenu.ascx. Because the VariationsFlagControl.xml file resides on the front-end Web server file system, the rendering cannot vary from site collection to site collection.

You can customize the default variations label control logic in one of three ways. Each approach has its own advantages and disadvantages, and you should consider them carefully before deciding which method to use.

  • Directly edit the VariationsLabelMenu.ascx file.

    This is the quickest way to edit the logic. You edit the logic in the VariationsLabelMenu.ascx file directly as you need on the front-end Web server file system.

    Note

    You must update the VariationsLabelMenu.ascx file on each of the servers. All site collections in the server farm will be tied to the custom variation root label logic you specify.

  • Create an .ascx file in the Master Page and Page Layouts Gallery.

    This approach's implementation is described in the first procedure, To create an .ascx file in the Master Page and Page Layouts Gallery. Like the previous method, this one also provides easy and rapid customization through direct editing, with no DLL compilation and deployment issues. In addition, because each site collection uses its own set of page layouts, this approach allows customization of variation label control logic on a site collection level. When you use this approach, you also must update the web.config file on each of the front-end Web servers.

    Warning

    Use caution when setting the AllowCompilation flag on the VariationsLabelMenu.aspx file. Using inline code can make it possible for someone to inject malicious code into the page.

  • Create a precompiled assembly.

    This method's implementation is described in the second procedure, To create a precompiled assembly. This approach poses no security risk related to opening a Master Page and Page Layouts Gallery item for inline code execution. Like the .ascx file creation method, customization is done on a site collection level. However, every time you need to change the Variation label control logic, you must recompile the assembly. As a result, this method offers a less rapid change-test-deploy cycle.

Note

You must deploy the assembly on all front-end Web servers.

To create an .ascx file in the Master Page and Page Layouts Gallery

  1. Upload VariationsLabelMenu.ascx to the site collection's Master Page and Page Layouts Gallery.

  2. To allow inline code execution of VariationsLabelMenu.ascx in the Master Page and Page Layouts Gallery, modify the web.config file as follows.

      <SharePoint>
         <SafeControls>
           <!-- marks the VariationsLabelMenu.ascx as safe -->
           <SafeControl Src="/_catalogs/masterpage/VariationsLabelMenu.ascx" Safe="True" AllowRemoteDesigner="True" />
         </SafeControls>
         <SafeMode ... >
           <!-- marks VariationsLabelMenu.ascx for ASP.NET compilation -->
           <PageParserPaths>
             <PageParserPath VirtualPath= "/_catalogs/masterpage/VariationsLabelMenu.ascx" 
               CompilationMode="Always"  
               AllowServerSideScript="False"
               AllowUnsafeControls="False" />
           </PageParserPaths>
         </SafeMode>
       </SharePoint>
    
  3. Replace the references to VariationsLabelMenu.ascx file on the front-end Web server file system with references to the VariationsLabelMenu.ascx file in the Master Page and Page Layouts Gallery You can do this in one of the following ways:

    • Completely remove the DelegateControl markup from the Default.Master master page, and embed a reference to the VariationsLabelMenu.ascx in the Master Page and Page Layouts Gallery.

    • Make a copy of the Default.Master master page and rename it, for example, Default2.master, and then have your site template use Default2.master. In Default2.master, you can replace the references to VariationsLabelMenu.ascx file on the front-end Web server file system with references to the VariationsLabelMenu.ascx file in the Master Page and Page Layouts Gallery.

  4. For the other publishing master files, you can replace the references to the VariationsLabelMenu.ascx file on the front-end Web server file system with references to the VariationsLabelMenu.ascx file in the Master Page and Page Layouts Gallery.

To create a precompiled assembly

  1. Copy the code from VariationsLabelMenu.ascx and create a composite control in your assembly DLL, using the VariationsLabelEcbMenu and VariationHierarchicalDataSource controls as child controls.

  2. Change the DelegateControl registration in \<Program Files>\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES\Publishing\VariationsFlagControl.xml to point to the composite control you created, which replaces the reference to VariationsLabelMenu.ascx on the front-end Web server file system.

    You can also completely remove the DelegateControl markup from the Default.Master master page and embed a reference to the composite control you created.

  3. For the other publishing master files, you can replace the references to VariationsLabelMenu.ascx with references to the composite control you created.