The SDK
documentation explains here [1] how
to override the ListFiledIterator to a Document Library by changing the
template. I need to change the Sharepoint SaveButton so that I can do some
additional task after or before saving.
These are
the steps I followed to do this:
- Create a custom type
inheriting from Sharepoint SaveButton.
- Override the protected
SaveItem method, and do the custom code which you want.
- Create a Control Template,
which overrides the default Sharepoint default implementation (here was I
spent lots of my time to figure it out to achieve this)
The key is
you have to replace the default declaration with your custom assembly and type,
which you created in step a.
Change the
control template of your custom control template from this
<wssuc:ToolBar
CssClass="ms-formtoolbar" id="toolBarTbl" RightButtonSeparator=" "
runat="server">
<Template_Buttons>
<SharePoint:CreatedModifiedInfo
runat="server"/>
</Template_Buttons>
<Template_RightButtons>
< SharePoint:SaveButton
runat="server"/>
<SharePoint:GoBackButton
runat="server"/>
</Template_RightButtons>
</wssuc:ToolBar>
to this:
<wssuc:ToolBar
CssClass="ms-formtoolbar" id="toolBarTbl" RightButtonSeparator=" "
runat="server">
<Template_Buttons>
<SharePoint:CreatedModifiedInfo
runat="server"/>
</Template_Buttons>
<Template_RightButtons>
<CustomOverrideControls:CustomSaveButton TemplateName="SaveButtonNew"
runat="server"/>
<SharePoint:GoBackButton
runat="server"/>
</Template_RightButtons>
</wssuc:ToolBar>
Define the
SaveButtonNew template as follows:
<SharePoint:RenderingTemplate
ID="SaveButtonNew" runat="server">
<Template>
<TABLE cellpadding=0
cellspacing=0 width=100%>
<TR><TD
align="<SharePoint:EncodedLiteral runat='server' text='<%$Resources:wss,multipages_direction_right_align_value%>'
EncodeMethod='HtmlEncode'/>" width=100% nowrap>
<asp:Button UseSubmitBehavior="false"
ID=diidIOSaveItem CommandName="SaveItem" Text="<%$Resources:wss,tb_save%>"
class="ms-ButtonHeightWidth"
accesskey="<%$Resources:wss,tb_save_AK%>"
target="_self"
runat="server"/>
</TD> </TR>
</TABLE>
</Template>
</SharePoint:RenderingTemplate>
This is
exact copy of the exisiting SaveButton RenderingTemplate declaration except the
ID, which currently tells as our custom control template name.
I also
attached a sample project which implements the custom type and the custom
control template file (CustomControl.ascx, the name really does not matter)
which needs to be placed in the "12 hive" ControlTemplates folder.
Cheers,
Murugan G.