murugangs

This site

Sponsors

  • MaximumASP
  • Social Bookmarking
    Online Shopping
    asp.net hosting
    UK online local dating

How to override or customize the Sharepoint SaveButton?

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:

  1. Create a custom type inheriting from Sharepoint SaveButton.
  2. Override the protected SaveItem method, and do the custom code which you want.
  3. 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="&nbsp;" 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="&nbsp;" 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.

Comments

Steve said:

Thanks a lot for this, hunted all over the place for some light on the limited documentation that MS give.

It's really helped me out.

# January 2, 2008 11:30 AM

spmikey said:

Please could you re-upload the CustomOverrideControls.zip file as it appears to be corrupted. Thanks.

# April 16, 2009 10:27 AM

muthujj said:

Hi

i downloaded your code and placed the ascx file in 12/controltemplates folder. i also built the solution and placed in GAC. i created new custom list. but i am seeing any change.

please provide some information about this. may be steps to install this.

please reply immedately

# June 17, 2009 1:06 AM

Self Service Site Creation trough code « Peter's Blog said:

Pingback from  Self Service Site Creation trough code « Peter's Blog

# September 9, 2009 4:14 PM

Ted said:

Why would you create your own rendering template for the button if your implementation is exactly the same as the SaveButton one you inherit from?

# September 17, 2009 6:48 AM

majox said:

Hi this is great tutorial (not big and easy to understand) I have tried to add some custom code on protected override bool SaveItem(), but the event does not fires. I am using only the part with the save button and only the savebutton class. Do you know why the event is not runnig ? Other events like OnInit and OnLoad fires correctly only the savebutton is not working :( Can you help me ?

# September 22, 2009 11:26 AM

Sai said:

Hi,

Nice post. I have similar requirement as yours.

I created a custom list form. Now, i want to override SaveButton. I followed the steps mentioned above, but could not achieve it.

I did following steps:

a. Created class library by extending SaveButton class and overriding SaveItem method (same as in your code)

b. Created a custom control (.ascx). - THe problem could be here.

c. Referenced the custom control from my custom list form page.

No luck.

Any inputs may help me in proceeding further.

# September 25, 2009 9:15 AM