1

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

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

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

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

4

2 回答 2

3

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

执行此操作的官方方法是创建列表定义并自定义列表模板。然后编辑编辑表单模板并根据需要包含尽可能多的 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>
于 2010-01-12T18:03:08.520 回答
0

您可以尝试使用 CopyUtil 重定向:http ://weblogs.asp.net/jan/archive/2008/02/26/copyutil-aspx-a-little-sharepoint-gem.aspx

链接 = " http://yoursite/_layouts/CopyUtil.aspx?Use=id&Action=dispform&ItemId=X&ListId=X&WebId=X&SiteId=X ";

Page.Response.Redirect(链接)

也许这会奏效

于 2010-01-13T15:07:53.377 回答