views:

538

answers:

4

Hello,

I'm having trouble with a custom control template.

My intention is to use a custom control template on a NewForm.aspx for a list.

  1. I have created a CustomTemplate.ascx file and this is deployed to 12/Template/CONTROLTEMPLATES

    < SharePoint:RenderingTemplate ID="CustomListForm" runat="server" >...

  2. I have modified the schema.xml file for the list to use my custom template:

    < Form Type="NewForm" Url="NewForm.aspx" WebPartZoneID="Main" Template="CustomListForm" />

My NewForm.aspx page still shows the default view however. This is for both new and existing lists based on my list template. I have tried restarting IIS around deployment but this doesn't help.

If I change the name of my template to "ListForm", this successfully overwrites the default template as expected, and I can see the change in existing and new lists.

I've looked for help on this site and Google, but can't find anything. Has anyone come across this before???

A: 

I would guess that you've got an error somewhere in the CustomTemplate.ascx -
could you post the code of the CustomTempate.ascx ?

A: 

All the Steps you have Performed is right. I have done similar things in past and was successful in get it working. Few things I would suggest is try writing following code see what is the template you getting.

        SPList oList=SPContext.Current.Web.Lists["YourList"];
        Console.WriteLine(oList.Forms[PAGETYPE.PAGE_NEWFORM].TemplateName);

If the above code is returning the right Template Name then there is no issue with the deployment / association.Something wrong with the Template itself. You can dig in to the SharePoint Log . You should get more information.

Kusek
Ok, checked the log after attempting to view the NewForm.aspx page and the following is written:High WARNING: Cannot change FormContext.FormMode to [Invalid] because it is already set to [New]Any ideas?
Jonny
A: 

Hmmm interesting point. Would you expect a syntax error to cause SharePoint to fall back on the default rather than throwing an error?

Here is the code from the CustomTemplate.ascx files:

<%@ 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="CustomListForm" runat="server">
    <Template>
            Test content
    </Template>
</SharePoint:RenderingTemplate>

Note that I copied the directives from the DefaultTemplates.ascx file. My file is located in the same directory.

Thanks very much for your help!

Jonny
+2  A: 

Make sure the TemplateName in your content type is null or empty string. TemplateName defined in ContentType will override any TemplateName defined in the list schema.

FYI, the out of the box content type 'Item' have NewFormTemplateName set to 'ListForm', this will override any custom template name defined in your list schema.

Fnop