Sharepoint: event sink: add position

Has anyone used the "ItemAdding" method successfully in the event receiver in Sharepoint for validation?

I think it just can't work fine for validation purposes because it seems like:

  • You cannot access the data you just entered into the form
  • If you add an error message, instead of displaying the form back with your error, Sharepoint will
    display a large page of ugly errors.

Here's what I've found so far on the internet for the ItemAdding method:

http://www.sharepoint-tips.com/2006/09/synchronous-add-list-event-itemadding.html

http://www.moss2007.be/blogs/vandest/archive/2007/07/20/wss-3-0-event-handler-pre-event-cancelling-issues.aspx

http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID=25

Anyway, if anyone has successfully used this method please tell me because I think it just broke / missing something!

Thank!

+2


source to share


2 answers


You cannot use ItemAdding to perform this kind of "friendly" validation. If you set e.Cancel = true and set e.ErrorMessage, sharepoint will redirect you to the standard error page and display your message. You cannot redirect it back to the form page.

Instead of trying to hack inline pages, you should use an infopath or aspx form bound to your content type. Infopath has built-in validation tools and with aspx forms that you create yourself, you can treat it like any web application and choose your own validation.



There is no easy way out.

-Oisin

+5


source


You can access the data that has been added to the form. Have a look at the .AfterProperties in add / update receivers.

An example would be .AfterProperties ["Title"].



I agree that error handling is a bit tricky, but I recommend that you do validation in event receivers in addition to having your UI do validation. If it is not a custom page, you can add JavaScript to existing pages using the Content Editor web part to perform validation.

+4


source







All Articles