1


I need to show an error message during in the ItemAdding event from a SP2013 event receiver.
I used this code in case of error:

properties.Status = SPEventReceiverStatus.CancelWithError;
properties.ErrorMessage = "My error";

I can see the error in the page but It shows also all the trace stack.
How can i show the more beauty sharepoint default error template. (with my error description)?
ErrorPage

2
  • Its better to do List/Field validation rather than doing it via Receiver. Commented Nov 18, 2014 at 16:48
  • I need that, I have some complex field validations (I am reading other lists)
    – Nk SP
    Commented Nov 18, 2014 at 16:50

2 Answers 2

2

To see a more "beautyful" error, you could enable custom errors in web.config

<customErrors mode="On" />

(Help: http://social.technet.microsoft.com/wiki/contents/articles/6171.sharepoint-2010-modify-web-config-to-display-error-details.aspx)

and then use this code:

properties.ErrorMessage = "Error";
properties.Status = SPEventReceiverStatus.CancelWithError;
0

You should use CancelWithRedirectUrl. Then show the error message on that custom page.

properties.ErrorMessage = "Error";
properties.Status = SPEventReceiverStatus.CanceWithRedirectUrl;
properties.RedirectUrl = url; //Pass the error message in query string

Create a custom page and on Page_Load read the query string and show it in a label.

http://waelmohamed.wordpress.com/2013/06/10/create-custom-error-page-for-sharepoint-event-receiver/

1
  • isn't this depricated?
    – Gwny
    Commented Sep 21, 2015 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.