Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

5 Answers 5

up vote 3 down vote accepted

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.

share|improve this answer
    
The picture in @JamesLove's answer is what the ErrorMessage would render as once you have the web.config file configured properly. –  SpartanDonut Feb 3 '12 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" ... –  spStacker Feb 3 '12 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 –  spStacker Feb 3 '12 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/… –  SpartanDonut Feb 3 '12 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 Feb 4 '12 at 0:04

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

share|improve this answer
1  
Hi James, thanks for pointing it out –  spStacker Feb 3 '12 at 20:58

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.

share|improve this answer
    
This has just helped me a lot, +1. –  DeeMac Jul 16 '12 at 12:49

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.

share|improve this answer

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

share|improve this answer
1  
I believe the error message shown in the Original Post is the product of the following the steps in that link... –  James Love Feb 3 '12 at 20:47
    
aah.. I thought he wanted to know more about the error itself.. –  Supriyo SB Chatterjee Feb 3 '12 at 21:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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