Update - March 1st, 2012

  Microsoft has issued a hotfix that provides support for event receiver custom error messages in a SharePoint 2010 Datasheet View!

 



Update - January 5th, 2012

  Great news...

The Microsoft Access Team has identified this limitation as a correctable issue and will be including a fix in a future cumulative update for Office 2010.  Once the associated CU is released (release date unknown), SharePoint developers will be able to provide custom error messages to end users via the Datasheet view in SharePoint 2010!

While recently working on a development project where event receivers and business validation logic were required, I came across a scenario that I wish to share with the community.

The concept is trivial:
  • Business logic validation fails based on data inputted by an end user in the logic of an event receiver (for example in  ItemAdding, ItemUpdating, ItemDeleting, etc), 
  • the event is cancelled and a custom error message is to be displayed to the end user. 
Here is a trivial example of what I needed to do within an event receiver:

properties.Status = SPEventReceiverStatus.CancelWithError;

properties.ErrorMessage = "My custom error message";

Using a Standard View this works like a charm - the event is cancelled and the end user sees my custom error message. Using a Datasheet View, well that's another story - the event is cancelled as intended, however displaying a custom error message to the end user is not possible...

It turns out that the display of custom error messages in a Datasheet View is not possible by design. I have confirmed this with the Microsoft SharePoint Development Support team. I was astonished to hear this for two reasons:
  1. Microsoft has climbed mountains over the years to ensure developers, regardless of their discipline (i.e. Web Development, Windows Development, etc), have the flexibility to display a meaningful custom error message in the UI for end users. As a List is a fundamental and core feature related to collaboration and information management within SharePoint I was surprised to learn that the ability for a developer to display a custom error message in a Datasheet View is not supported by design.

  2. This limitation has been a known since the ActiveX Control responsible for the Datasheet View was developed by Microsoft circa 2005. Yes, that was around six (6) years ago. This limitation has persisted over years through all of the SharePoint 2007/WSS 3.0 product cycle and is still a limitation in SharePoint 2010 and SharePoint Foundation. 
For additional technical information - the Datasheet View utilizes the lists.asmx web service to interact with SharePoint to process requests and to deliver responses for end users asynchronously. Redirection is not possible due to this architecture in the event you wish to redirect to a custom error page either. The best you can do to notify a user with a meaningful error message in the described scenario is to send them an email with the details. You could also write a log entry with the error details, however this does not assist the user to tell them what they did 'wrong' while using a Datasheet View.

The Datasheet view does a great job of determining if items are out of sync and it has no issues that I have found even though it does processing events via web services asynchronously from the ActiveX control. The ActiveX control from my testing and from the comments from Microsoft does not have any impact on the processing of events or business validation rules on the server side. The only item that I call a limitation is custom error message reporting when a developer cancels an event. 


After searching online for an authoritative answer for this online which yielded no definitive answer, I decided to share this experience with the community. My intent for sharing this information is to educate and inform developers of this limitation of the Datasheet View and to (hopefully) assist in making SharePoint better. SharePoint is an amazing platform and I wish for it to be the best that it can be. This was the first project where I was tasked with developing event receivers to interact specifically with a Datasheet view which is why I have not come across this limitation before. I understand that this by design limitation is likely not a high priority for the SharePoint team given other things they are working on such as feature enhancements, service packs, hot fixes and likely the next version of SharePoint.

I hope that this explanation will assist someone looking for an answer related to this limitation and will save them some time as well. I also hope that this limitation is addressed at some point in the future by the SharePoint team. In conclusion, it is my belief that regardless of the view chosen for or by users to interact with SharePoint list data, a developer should have the ability to display a custom error message when appropriate.
 

Have you experienced this Datasheet View limitation before? Add to this wiki article or post a comment and share your experience.