SPContext.Current.FormContext.OnSaveHandler not firing when SPControlMode is New

坚强是说给别人听的谎言 提交于 2020-02-02 06:28:04

问题


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
}

来源:https://stackoverflow.com/questions/4229657/spcontext-current-formcontext-onsavehandler-not-firing-when-spcontrolmode-is-new

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!