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)?

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

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;

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.


  • isn't this depricated? – Gwny Sep 21 '15 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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