Tuesday, May 20, 2008

Customizing the New Form toolbar

So, here's the requirement:

Add a control (for arguements sake a link button) to the NewForm.aspx toolbar for a specific list definition.

Sounds simple doesn't it? And in fact it is simple... Still took me 3 days to figure out!!

What you need to do is a write an web user control that defines how you want your toolbar to look like via a SharePoint rendering template. Something like this:


Note the name of the rendering template - CustomToolBar
Note also the fact that the attachment button and the link button both lack ID tags.


Right. Save that .ascx file to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES

iisreset

Now, in your list schema, look riiiiiiiight at the bottom for the forms tag. See this tag?


<form type="NewForm" url="NewForm.aspx" webpartzoneid="Main"/>

You need to add a ToolbarTemplate attribute. Why did this take me three days? Because the toolbartemplate attribute is not declared!!!! It will be underlined in blue, but the solution will deploy. Don't try this in a content type, the content type feature will not be activated.

Anyway, at the end your NewForm declaration should look something like this:
<form type="NewForm" url="NewForm.aspx" webpartzoneid="Main" toolbartemplate="CustomToolBar"/>

And what you end up with should be: