EDIT UPDATE: This post is followed up in Following up on edit, display and new form
I am doing a project for a client who wants a listitem details page to be customized (DispForm, EditForm and NewForm that is). At first this seemed like a trivial task, but I found out it would involve lots of research and editing.
First of all, to customize DispForm, EditForm and NewForm you have to make up your mind on one of two approaches (there might be more):
- Do you want the customization to be bound to a specific content type?
- Or do you want it to be tied to a specific list template?
I choose the first option. I tried the second but I couldn't make it work... The following is what I had to customize to achive my goal in this matter.
- Customize the ContentType-element in my feature
- Create an ascx to hold my customization
- Create new RenderTemplates
- Override existing RenderTemplates
- Deploy customization
First off, you have to make an XmlDocuments-element as a child element to your ContentType-element in your feature:

In the above CAML I've bound the customization to the content type by adding the XmlDocument child-element to the ContentType-element. In this example I've used the MyListForm-template for all the scenarios: display, edit and new. This means, it uses the same rendering for the three scenarios (don't worry, kids, it will render textboxes and the like when in new- or edit-mode, I'll get back to that).
Next off, I've created an ascx-control which is deployed to 12/TEMPLATES/CONTROLTEMPLATES. The name of the ascx doesn't matter, what matters is what is inside the ascx! In the ascx you have your rendering-templates. This is basically how you want your view to be rendered. This is what's inside the ascx:
<%@ Control Language="C#" AutoEventWireup="false" %>
<%@Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.WebControls"%>
<%@Register TagPrefix="SPHttpUtility" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.Utilities"%>
<%@ Register TagPrefix="wssuc" TagName="ToolBar" src="/_controltemplates/ToolBar.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBarButton" src="/_controltemplates/ToolBarButton.ascx" %>
<SharePoint:RenderingTemplate ID="MyListForm" runat="server">
<Template>
<div id="text">
<wssuc:ToolBar CssClass="ms-formtoolbar" id="toolBarTbltop"
RightButtonSeparator=" " runat="server">
<Template_RightButtons>
<SharePoint:NextPageButton runat="server"/>
<SharePoint:SaveButton runat="server"/>
<SharePoint:GoBackButton runat="server"/>
</Template_RightButtons>
</wssuc:ToolBar>
<SharePoint:FormToolBar runat="server"/>
<SharePoint:ListFieldIterator runat="server"/>
</div>
</Template>
</SharePoint:RenderingTemplate>
<SharePoint:RenderingTemplate ID="DisplayCompositeField" runat="server">
<Template>
<h3><SharePoint:FieldLabel runat="server"/></h3>
<p><SharePoint:FormField runat="server" /></p>
<SharePoint:AppendOnlyHistory runat="server"/>
</Template>
</SharePoint:RenderingTemplate>
<SharePoint:RenderingTemplate ID="ListFieldIterator" runat="server">
<Template>
<SharePoint:CompositeField runat="server"/>
</Template>
</SharePoint:RenderingTemplate>
<SharePoint:RenderingTemplate ID="CompositeField" runat="server">
<Template>
<h3><SharePoint:FieldLabel runat="server"/></h3>
<p><SharePoint:FormField runat="server"/></p>
<p><SharePoint:FieldDescription runat="server"/></p>
<SharePoint:AppendOnlyHistory runat="server"/>
</Template>
</SharePoint:RenderingTemplate>
Above code explained: Part of it has been taken from the DefaultTemplates.ascx in the 12/TEMPLATES/CONTROLTEMPLATES-dir. The SharePoint:RenderTemplate with the ID="MyListForm" is my own and the ID is correpsonding to ID in the ContentType's Display-, Edit- and New-elements. The MyListForm is a "copy" of the ID="ListForm"-template in DefaultTemplates.ascx, just customized. As I said, you can assign different rendering-templates to the three scenatios, I choose the same for all of them.
To accomplish a custom rendering to my liking, I had to override the DisplayCompositeField (which is the template used for the display-mode), the ListFieldIterator-template, which iterates fields (regardless of the display/new/edit-mode) and the CompositeField-template which renders the inputs when in edit mode.
(As of writing I've found out that the overridden templates also has effect on the rendering of all other listitems, and not just the rendering of the contenttype in question (Employee Item) :( I'll have to fix this later, if you find a way to do this, please let me know)
When deploying, make sure your ascx goes to the 12/TEMPLATES/CONTROLTEMPLATES-dir. Do an IISRESET because SharePoint is caching the contents of the renderingtemplates. IISRESET is done if you perform a real deploysolution or upgradesolution with stsadm, but not if you just manually copy the ascx to the 12/TEMPLATES/CONTROLTEMPLATES-dir.
EDIT UPDATE: This post is followed up in Following up on edit, display and new form