Sharepoint 项目更新事件 - 取消事件返回编辑表单页面?

发布于 2024-08-17 09:52:26 字数 362 浏览 1 评论 0原文

我有一个内容类型的事件接收器,用于验证 ItemUpdating 事件中的某些数据。如果我取消事件(例如,某些数据无效),我将属性取消设置为 true:

properties.Cancel = true;
properties.ErrorMessage = "...";

SharePoint 正常取消更新事件,但显示标准 SharePoint 错误页面(带有指定的消息)。唯一的问题是,我收到一个抱怨,这实际上并不是很有用 - 我们应该返回到 EditForm 页面,以便可以更新详细信息。

有人做过吗,有简单的方法吗?我唯一的建议是我可以实现自己的错误页面,但这听起来对(理论上)简单的过程来说是一个相当沉重的解决方案。

I have an event receiver for a content type to validate some data in the ItemUpdating event. If I cancel the event (some of the data isn't valid for example), I set the properties cancel to true:

properties.Cancel = true;
properties.ErrorMessage = "...";

SharePoint cancels the updating event ok, but shows the standard SharePoint error page (with the specified message). Only problem is, I've got a complaint that this isn't actually very useful - we should return to the EditForm page so the details can be updated.

Has anyone done this, is there an easy way? The only suggestion I've had is that I can implement my own error page, but that's sounding quite a heavy solution to a (theoretically) simple process.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

峩卟喜欢 2024-08-24 09:52:26

您可以尝试在 ErrorMessage 中输出 HTML 代码(也包括 javascript)。但即使您这样做,问题是您无法安全地返回用户输入的数据。要么进行 HTTP/301 重定向,然后加载新页面,要么让客户端使用 JavaScript 执行 history.back(),然后浏览器可能会重新加载页面。

执行此操作的官方方法是创建列表定义并自定义列表模板。然后编辑编辑表单模板并根据需要包含尽可能多的 ASP.Net 验证器控件。然后,根据需要实现服务器端逻辑。本文介绍了该技术:http://msdn.microsoft.com/en- us/library/aa543922.aspx

编辑:要附加自定义控件来编辑特定内容类型,请将 XmlDocuments 部分添加到 ContentType 定义中。例如,像这样

<ContentType
    ..........

    <XmlDocuments>
      <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
        <FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
          <Display>ContentTypeName_DispForm</Display>
          <Edit>ContentTypeName_EditForm</Edit>
          <New>ContentTypeName_NewForm</New>
        </FormTemplates>
      </XmlDocument>
    </XmlDocuments>
  .......

然后您创建自己的 yoursolution_controltemplates.ascx 文件,其中也包含以下块:”

<SharePoint:RenderingTemplate ID="ContentTypeName_DispForm" runat="server"> 
<Template>
      <!-- put whatever controls you need here, we typically create a 
           separate custom control which implements everything-->
</Template>
</SharePoint:RenderingTemplate>

You could try to output HTML code (which includes javascript as well) in the ErrorMessage. BUT even if you do, the problem is that you have no safe way back to the data the user has entered. Either you make a HTTP/301 redirect and then it's a new page load, or you make the client go history.back() with JavaScript and then the browser may reload the page.

The official way of doing this is that you create a list definition and customize the list template. Then you edit the edit form template and include as many ASP.Net validator controls as needed. Then, implement the server side logic as you need. This article explains the technique: http://msdn.microsoft.com/en-us/library/aa543922.aspx

EDIT: To attach a custom control for editing of a specific contenttype, you add an XmlDocuments section to your ContentType definition. For instance, like this

<ContentType
    ..........

    <XmlDocuments>
      <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
        <FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
          <Display>ContentTypeName_DispForm</Display>
          <Edit>ContentTypeName_EditForm</Edit>
          <New>ContentTypeName_NewForm</New>
        </FormTemplates>
      </XmlDocument>
    </XmlDocuments>
  .......

Then you create your own yoursolution_controltemplates.ascx file, which contains as well such blocks:"

<SharePoint:RenderingTemplate ID="ContentTypeName_DispForm" runat="server"> 
<Template>
      <!-- put whatever controls you need here, we typically create a 
           separate custom control which implements everything-->
</Template>
</SharePoint:RenderingTemplate>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文