当 SPControlMode 为 New 时,SPContext.Current.FormContext.OnSaveHandler 不会触发

发布于 2024-10-03 15:00:12 字数 770 浏览 1 评论 0原文

我有一个 Web 部件,用于将一些自定义控件添加到 SharePoint ListItem 的新建、编辑和显示表单中。我为 SPContext.Current.FormContext.OnSaveHandler 添加了一个处理程序来更新该项目。我使用 SharePoint Designer 将 Web 部件添加到“编辑”和“新建”表单中,并隐藏(设置 IsVisible=False)默认情况下放入的 DataFormWebPart。编辑项目时一切正常。我的 OnSaveHandler 函数被调用并更新 SPListItem。问题出在新项目上。除非 DataWebFormPart 可见,否则不会调用 OnSaveHandler 函数。我没有对 Web 表单进行任何其他更改,但切换了 DataFormWebPart 的可见性。有什么想法我做错了吗?

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
}

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
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文