Partager via


How to customize the Item Form pages for the SharePoint Lists such as NewForm.aspx, DispForm.aspx and EditForm.aspx

Item form pages are the pages created based on the "Forms.aspx" as the setup page
which is available under 12/Templates/Pages folder.

1. All the templates for the NewForm, EditForm and DispForm (Item Form pages) are
defined in the defaulttemplates.ascx

2. This templates are associated with the List through content type

3. The FormTemplates of the NewForm, EditForm and DispForm are definied in the
content type as folows

<ContentType ID="0x01"
Name="$Resources:Item"
Group="$Resources:List_Content_Types"
Description="$Resources:ItemCTDesc"
Version="0">
<FieldRefs>
<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title"
Required="TRUE" ShowInNewForm="TRUE" ShowInEditForm="TRUE"/> <!-- Title -->
</FieldRefs>
<XmlDocuments>
<XmlDocument
NamespaceURI="https://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<FormTemplates
xmlns="https://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<Display>ListForm</Display>
<Edit>ListForm</Edit>
<New>ListForm</New>
</FormTemplates>
</XmlDocument>
</XmlDocuments>
</ContentType>

4. The "ListForm" template which have been in the above Content Type you can find
it in the DefaultTemplates.ascx control

5. Create a custom Defaulttemplates.ascx and create the custom rendering template
based on the ListForm and make ur changes (Including or Excluding control) Note :
ListFieldIteratorControl is the one which renders the Fields for the List in the
item form pages

6. Following are the steps to create custom defaulttemplates.ascx

1. Create a new custom Template: say name: CustDefaultTemplates.ascx and save it
in the folder: C:\Program Files\Common Files\Microsoft Shared\web server
extensions\12\TEMPLATE\CONTROLTEMPLATES

a. Open DefaultTemplates.ascx file (located at the same path mentioned above). Copy
the following lines from the file and add to the CustDefaultTemplate.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" %>

b. Now, in DefaultTemplates.ascx look for line:
<SharePoint:RenderingTemplate ID="ListForm" runat="server">

c. Copy this complete node and paste in the CustDefaultTemplate.ascx below the
lines added above.

d. Now, change the ID="ListForm" to any other ID; example: ID="CustListForm" in
CustDefaultTemplate.ascx

e. Save the File CustDefaultTemplate.ascx

7. Create a custom content type and render the "CustomListForm" as the template for
the New, Edit and Display form.

8. Attache the custom content type with the List.

9. Now whenever you create new, Edit and Dispform for this List it will render your
custom template instead of OOb template.

Comments