3

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 put 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
}
Tim Scarborough
  • 1,270
  • 1
  • 11
  • 22
  • I am having the exact same issue. On edit my OnSaveHandler is getting raised SPContext.Current.FormContext.OnSaveHandler += new EventHandler(MyHandler); however when saving new items (document sets) with custom fields this event is not being raised – David Jun 07 '11 at 21:15

0 Answers0