Adding a custom error message to the Event Receiver

When we created our Event Receiver in the previous recipe, we saw that if we cancelled the insertion of an item into a list (due to a data validation error), an ugly error message appeared indicating that an Event Receiver had cancelled the request. It is difficult for users to comprehend this error message, it does not indicate that the error is due to data validation and that there is nothing wrong with SharePoint. In this recipe, we will customize this error message that indicates what the error is.

Getting ready

The solution from the previous recipe is used for further modifications. You should complete the previous recipe successfully to follow this one.

How to do it...

  1. If you have closed your ...

Get Microsoft SharePoint 2010 Development with Visual Studio 2010: Expert Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.