views:

730

answers:

2

Anybody used the "ItemAdding" method successfully in an Event Receiver in Sharepoint for validation?

I think it just can't work properly for validation purposes because it seems that :

  • You can't access the data you just entered in a form
  • If you add an error message, instead of displaying the form back with your error, Sharepoint
    display the big ugly error page.

Here's what I found so far on the web 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 somebody successfully used that method, please tell me how because I think that it's just broken/missing something!

Thanks!

+2  A: 

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

Rather than trying to hack the built in pages, you should use an infopath or aspx form bound to a content type. Infopath has built-in validation controls and with aspx forms you build yourself you can treat it like any web app and choose your own validation.

No easy way out here I'm afraid.

-Oisin

x0n
A: 

Having same issue. Plz reply if somebody have a answer. Thank in advance, Hiral

Hiral