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?
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.
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:
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.
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.
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