0

I am working on creating event receiver on a specific custom list using visual studio 2010. Below is the screenshot of the error message set on properties. ErrorMessage I'm interested in knowing how can we customize this form? Any suggestions? enter image description here

5 Answers 5

3

If you do something like the following in your code:

properties.ErrorMessage = "Access Denied: You do not have proper permissions to delete this item.";
properties.Cancel = true;

Then make sure to reverse the updates you made to the web.config file to show the full errors. (Reference)

If all is done correctly you should see a screen very similar to SharePoint's "Unknown Error" but it will display the value in ErrorMessage instead.

6
  • The picture in @JamesLove's answer is what the ErrorMessage would render as once you have the web.config file configured properly. Commented Feb 3, 2012 at 20:36
  • Hi Tyler, it worked, i am getting the same page error as james screenshot ...i change the web.config file SafeMode tag callstack attribute.......From <SafeMode CallStack="true" ... To <SafeMode CallStack="false" ...
    – SandeshR
    Commented Feb 3, 2012 at 20:55
  • I am getting a Correlation ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ? in the error box..is there any way i can make it invisible on the error form..Thanks
    – SandeshR
    Commented Feb 3, 2012 at 20:57
  • 2
    Not that I am aware of but I'd be happy to be proven wrong. You could create a custom application page to handle for this and then use properties.RedirectUrl to navigate to it. zimmergren.net/technical/… Commented Feb 3, 2012 at 21:02
  • You should only get an Correlation ID if a real exception has been raised by SharePoint. I believe there is still a problem with your code, and the error message is a genuine one rather than the one you have created.
    – James Love
    Commented Feb 4, 2012 at 0:04
4

I think that error is caused by something else in your event receiver code, the error message shown by properties.ErrorMessage should be something like this:

enter image description here

0
2

As James Love pointed out, the screenshot in the original question is an IIS error page, not a SharePoint error page. Your code likely has a run-time error and is throwing an exception (specifically in this case, you are doing something wrong with an SPWeb or SPSite object).

If you want to customize that page you need to fiddle with your web.config, but I would not recommend it. Fix the error before proceeding further.

To show a custom SharePoint error page in your event receiver, use the following code in your method:

properties.Cancel = true; 
properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl; 
properties.RedirectUrl = "/_layouts/SomeCustomErrorApplicationPage.aspx?Error=" + errorMessage;

Then deploy that Application page there and have it display the error message in the query string.

1
  • This has just helped me a lot, +1. Commented Jul 16, 2012 at 12:49
1

If you want your own Error message, you have to make an application page (e.g. "error.aspx") and design it as per your requirement. Then set some properties like:

properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
properties.RedirectUrl = "Error.aspx page's url";

Then this page will be displayed instead of the server error page.

0

To obtain more information regarding your error - make changes to the Web.Config sections are described in this post - SharePoint Web.Config: How to Show Full Errors

2
  • 1
    I believe the error message shown in the Original Post is the product of the following the steps in that link...
    – James Love
    Commented Feb 3, 2012 at 20:47
  • aah.. I thought he wanted to know more about the error itself.. Commented Feb 3, 2012 at 21:13

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.