2

I'm a novice Sharepoint developer, so please forgive what is probably a very simple question.

I have an event receiver on a custom list in Sharepoint 2010. I need to be able to display custom error messages, and have it working fine in the standard Add New Item form. I just found out that some of the users of this list prefer to add items in datasheet view, so I found how to display a custom error message in datasheet view. The code to do the error handling is different, though, so I need some way to programmatically tell if the item was added via datasheet view. I have searched and searched and have been unable to find a way to do this. Does anyone know how?

Here's my code, with an imaginary boolean, isDataSheetView, added showing what I'd like to be able to do:

//somehow determine if it's datasheet view, and set isDataSheetView accordingly

if (isDataSheetView)
{
    // Cancel with error, for datasheet view
    properties.Status = SPEventReceiverStatus.CancelWithError;
    properties.ErrorMessage = errorMsg.ToString();
}
else
{
    //Cancel with redirect URL, for non-datasheet entries
    properties.Status = SPEventReceiverStatus.CancelWithRedirectUrl;
    properties.RedirectUrl = "/_layouts/CheckReagentInventory/CasError.aspx?Error=" + HttpUtility.HtmlEncode(errorMsg.ToString());
    this.EventFiringEnabled = false;
}

Thanks for any advice, Liam

0

This is a known limitation of the datasheet because it uses the lists.asmx web service on the backend. There really is no way to do what you want to do cleanly. Here re your options as far as I can see:

  1. Create a custom UI using something like Kendo UI's gridview and ListData.svc so that you can add your own validation in between SharePoint and the user. Disabl datasheet on the list and then create a custom action button to access your application page with the custom UI.

  2. Not use CancelWithRedirect and instead use another method to handle the error state that could be applicable to both views. One possible solution might be to add a field called Exception Status and update that field with an appropriate value to alert the user. You could also use an email alert to notify them.

My choice would probably be the first. If you'd like some additional information on the 1st option, just create another question and add the link as a comment here. I have a lot of experience with ListData.svc and could help you out with some of its nuances.

|improve this answer|||||
  • Thanks, Robert. Sorry I didn't see your answer earlier. I thought I had set my account to email me when I received replies, but I got no email. I appreciate your advice. I'll look into this further, and may post a new question on the custom ui / ListData.svc approach. Thanks! – Liam Graham Mar 27 '14 at 4:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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