SPContext.Current.FormContext.OnSaveHandler not firing when SPControlMode is New
I've got a web part that I'm using to add some custom controls to the New, Edit and Display forms for a SharePoint ListItem. I added a handler for SPContext.Current.FormContext.OnSaveHandler to update the item. I add my web part to the Edit and New forms using SharePoint Designer and hide (set IsVisible=False) for the DataFormWebPart that's p开发者_C百科ut in by default. Everything works fine when editing an item. My OnSaveHandler function is called and I update the SPListItem. The problem is with a new item. The OnSaveHandler function is not called unless I have the DataWebFormPart visible. I make no other changes to the web form but toggle the visibility of the DataFormWebPart. Any ideas what I'm doing wrong?
if (SPContext.Current.FormContext.FormMode == SPControlMode.Edit ||
SPContext.Current.FormContext.FormMode == SPControlMode.New)
{
SPContext.Current.FormContext.OnSaveHandler += FormContext_OnSave;
}
....
protected void FormContext_OnSave(object sender, EventArgs e)
{
//update the list item
}
精彩评论