Question

I implemented an event receiver and attached it to a MOSS 2007 document library. I overrode the synchronous itemUpdating method and perform some validation before letting the update operation proceed. In case validation fails, I use the following code to cancel the update and indicate an error to the user:

public override void ItemUpdating(SPItemEventProperties properties)
{
    base.ItemUpdating(properties);
    // Perform some validation...
    if (/*validation fails*/)
    {
        properties.Status = SPEventReceiverStatus.CancelWithError; // line 1
        properties.Cancel = true;                                  // line 2
        properties.ErrorMessage = "Validation error";              // line 3
    }
}

I expected to see the SharePoint error page with a display of the error message. Instead, I see the rather unamiable IIS server error page with the full stack trace.

I switched around lines 2 and 3, and I even replaced SPEventReceiverStatus.CancelWithError with SPEventReceiverStatus.CancelNoError, to no avail. Any ideas???

Was it helpful?

Solution

The "yellow" ASP.NET error page is probably due your "dev" web.config configuration that shows up raw errors (see How to set customErrors attribute in sharepoint 2013?).

However, ErrorMessage will always end-up with an error message to the end-user, just less ugly than the yellow one. No way to display a nice warning box :(

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top