我如何从服务器端事件接收器返回自定义错误消息,并在创建/编辑列表表单中显示它 [英] How i can return a custom error message from our server side event receiver, and show it inside the Create/Edit list forms

查看:105
本文介绍了我如何从服务器端事件接收器返回自定义错误消息,并在创建/编辑列表表单中显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SharePoint on-premises 2013,我创建了一个服务器端事件接收器,具有以下主要属性: -

<接收> 
< Name> EventReceiver1ItemUpdating< / Name>
< Type> ItemUpdating< / Type>
< Assembly> $ SharePoint.Project.AssemblyFullName $< / Assembly>
< Class> OrderManagement.EventReceiver1.EventReceiver1< / Class>
< SequenceNumber> 10000< / SequenceNumber>
<同步>同步< /同步>
< / Receiver

并且事件接收器的范围是在网络级别。


并在<$ c内$ c> ItemUpdating 方法,我正在做一些检查,如果检查失败,我将返回如下错误信息: -

 public override void ItemUpdating(SPItemEventProperties properties)
{
base.ItemUpdating(properties);
//代码用于检查某些条件..
string ErrorMessage ="此阶段的项目只能由"分配给用户"编辑;
properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = ErrorMessage;
}

但问题是错误信息将显示如下: -



虽然我希望显示错误消息在编辑表单本身内部为红色 .. 所以我需要更改为在我的事件接收器中实现这个? 。根据我的阅读,我们可以通过事件接收器实现这个
,但不确定为什么这在我的情况下不起作用?在我的情况下,错误消息显示在单独的错误页面内(如上所示),而不是显示在编辑表单内..




解决方案

嗨johnjohn123,


添加 

  properties    Cancel     =     true  ;  


更改/验证web.config之后  Callstack =" false" ;;和customErrors =" On"。


这应该可以解决问题。



P


I am working on SharePoint on-premises 2013, and i have created a server-side event receiver, with the following main properties:-

<Receiver>
    <Name>EventReceiver1ItemUpdating</Name>
    <Type>ItemUpdating</Type>
    <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
    <Class>OrderManagement.EventReceiver1.EventReceiver1</Class>
    <SequenceNumber>10000</SequenceNumber>
    <Synchronization>Synchronous</Synchronization>
</Receiver

and the event receiver is scoped at the web level.

And inside the ItemUpdating method , i am doing some checks, and if the checks fail, i will return an error message as follow:-

public override void ItemUpdating(SPItemEventProperties properties)
{
    base.ItemUpdating(properties);
    //code goes here for checking some conditions..
    string ErrorMessage = "Item at this stage can only be edited by the Assign To User";
    properties.Status = SPEventReceiverStatus.CancelWithError;
    properties.ErrorMessage = ErrorMessage;
}

but the problem is that the error message will be shown as follow:-

while i want the error message to be shown inside the Edit form itself in Red color.. so what i need to change to have this implemented inside my event receiver? .as per my reading that we can achieve this with event receivers, but not sure why this is not working in my case? where in my case the error message is being shown inside a separate error page (as shown above), rather than being shown inside the Edit form..

解决方案

Hi johnjohn123,

Add 

properties.Cancel = true;

After that change/validate the web.config Callstack="false"; and customErrors = "On".

That should do the trick.

P


这篇关于我如何从服务器端事件接收器返回自定义错误消息,并在创建/编辑列表表单中显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆