How to: Override a Default Control Template

Applies to: SharePoint Foundation 2010

You can override an existing default form template that is installed with Microsoft SharePoint Foundation by adding an .ascx file that defines a custom user control to %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\CONTROLTEMPLATES. The custom control template must have the same identifier (ID) as the default template.

Example

The following control template example overrides the default control template whose ID equals DocumentLibraryForm. The template adds a message to the bottom of the form with a link to another page.

<SharePoint:RenderingTemplate ID="DocumentLibraryForm" runat="server">
  <Template>
    <SharePoint:InformationBar runat="server"/>
    <wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbltop" RightButtonSeparator="&nbsp;" runat="server">
      <Template_RightButtons>
        <SharePoint:SaveButton TabIndex=1 runat="server"/>
        <SharePoint:GoBackButton runat="server"/>
      </Template_RightButtons>
    </wssuc:ToolBar>
    <SharePoint:FormToolBar runat="server"/>
    <SharePoint:FormComponent TemplateName="DocumentLibraryFormCore" runat="server"/>
    <div style="padding-top: 40px; font: 8pt Tahoma;">
      <span style="color: red; font-weight: bold">Warning:</span>   This site contains customer data and information. <a href="_layouts/moreinfo.aspx">More information on customer data protection.</a>
    </div>
  </Template>
</SharePoint:RenderingTemplate>

To create a custom control template file for document libraries

  1. In Microsoft Visual Studio, create an a user control (.ascx file) as described in How to: Create a User Control for a SharePoint Application Page or Web Part.

  2. Add a template definition to the .ascx file that overrides a specific default control template, such as the previous example.

  3. Reset Internet Information Services (IIS) so that changes can take effect.

  4. Navigate to a form for an item in a document library to see the changes.