Sharepoint:事件接收器:项目添加
有人在 Sharepoint 的事件接收器中成功使用“ItemAdding”方法进行验证吗?
我认为它无法正常用于验证目的,因为它似乎:
- 您无法访问刚刚的数据 在表单中输入
- 如果添加错误消息, 而不是显示表单 返回您的错误,Sharepoint
显示又大又丑的错误页面。
这是我迄今为止在网上找到的 ItemAdding 方法:
http://www.sharepoint-tips.com/2006/09/synchronous-add-list-event-itemadding.html
http://www.synergyonline.com/blog/blog-moss/Lists/Posts/Post.aspx?ID= 25
无论如何,如果有人成功地使用了该方法,请告诉我如何使用,因为我认为它只是损坏/丢失了一些东西!
谢谢!
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.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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能使用 ItemAdding 来执行这种“友好”的验证检查。如果您设置 e.Cancel = true 并设置 e.ErrorMessage,sharepoint 会将您重定向到标准错误页面并显示您的消息。您无法将其重定向回您的表单页面。
您应该使用绑定到内容类型的 infopath 或 aspx 表单,而不是尝试破解内置页面。 Infopath 具有内置的验证控件,并且使用您自己构建的 aspx 表单,您可以像任何 Web 应用程序一样对待它并选择您自己的验证。
恐怕没有简单的出路。
-奥辛
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
您可以访问刚刚添加到表单中的数据。查看添加/更新事件接收器中的properties.AfterProperties。
一个例子是properties.AfterProperties[“Title”]。
我同意错误处理有点困难,但我建议您除了让 UI 进行验证之外,还在事件接收器中进行验证。如果它不是自定义页面,则您可以使用内容编辑器 Web 部件将 JavaScript 添加到现有页面以进行验证。
You can access data that was just added in the form. Look at properties.AfterProperties in the adding/updating event receivers.
An example would be properties.AfterProperties["Title"].
I agree that error handling is a little hard, but I recommend that you do validation in your event receivers in addition to having your UI do validation. If it is not a custom page, then you can add JavaScript to existing pages using a Content Editor Web Part to do the validation.