Thursday, March 21, 2013

Setting Custom ListFormWebPart Parameters in List Definition

In order to set custom ListFormWebPart parameters when defining list definition schema, you need to modify Form tag in schema.xml. Please refer to the following sample, used to add CSRRenderMode property to ListFormWebPart and set it to ServerRender:

<Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" UseDefaultListFormWebPart="False">
    <WebParts>
      <AllUsersWebPart WebPartZoneID="Main" WebPartOrder="1">
        <![CDATA[
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
  <Assembly>Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, 
         PublicKeyToken=71e9bce111e9429c</Assembly>                         
  <TypeName>Microsoft.SharePoint.WebPartPages.ListFormWebPart</TypeName>
  <PageType>PAGE_NEWFORM</PageType>
  <CSRRenderMode xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">ServerRender</CSRRenderMode>

</WebPart>]]>
      </AllUsersWebPart>
    </WebParts>
</Form>

You can change Microsoft.SharePoint assembly reference to 14.0.0.0 or 12.0.0.0 to use it with SharePoint 2010 or SharePoint 2007 respectfully.

4 comments:

  1. Is there a way to Set this property for a List using Code. I can see the enum CSRRenderMode in Microsoft documentation but not sure how to use it.

    Thanks,
    Sandy

    ReplyDelete
    Replies
    1. CSRRenderMode property is not a List property, but ListFormWebPart property. In order to change it from code, you need to access ListFormWebPart web part (usually placed on the List form), and just change its properties.

      Delete
    2. What if I add the item to the list programatically using CSOM/JSOM etc. Also does it work for other event receivers like web adding etc.

      Delete
    3. It would not work whenever you do not have HttpContext. But if you do, theoretically it should work. Never tried it like this though.

      Delete