开发者

Override SharePoint:SaveButton click event Share Point

I have created a custom Share Point 2010 webpart, in which i take input from user, basically it is a new form. I have a predefined list for data storage, I used

<SharePoint:FormField ID="id" runat="server" ControlMode="New" FieldName="name" > 
</SharePoint:FormField>

and used

 <SharePoint:SaveButton ID="SP_save" runat="server" ControlMode="New" >   
 </SharePoint:SaveButton>

to save the form fields. All it is working fine, it takes the valid data in inp开发者_运维问答ut and shows proper validation messages. but there is a problem i am facing, since i have no access to SharePoint:SaveButton click event and can't override it to my custom event

for example, I have a requirement to save the data in list and then perform some another task based on input, so how i do that


You need to create a custom SaveButton and override the SaveItem method.

Code:

namespace CustomOverrideControls
{
    public class CustomSaveButton : SaveButton
    {
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }

        protected override bool SaveItem()
        {
            // Do the custom code here
            return base.SaveItem();
        }
    }
}

Markup:

<CustomOverrideControls:CustomSaveButton ID="SP_save" runat="server"
    ControlMode="New">
</CustomOverrideControls:CustomSaveButton>

I took the above example from the article How to override or customize the SharePoint SaveButton? that also contains a complete project for download.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜