注册已注册的 SharePoint 事件接​​收器

发布于 2024-08-03 13:34:10 字数 388 浏览 0 评论 0原文

我正在针对列表编写一个 Web 部件。我在 Web 部件中做的第一件事是验证我的自定义事件接收器是否已在列表中注册。如果不是,我会以编程方式注册。

我注意到,如果我尝试注册一个已经注册的事件,我不会收到任何错误,也不会注册任何“额外”事件。

我的问题是:每次 Web 部件加载时注册事件,而不是迭代事件接收器列表中的每个事件并进行比较以查看每个事件接收器是否存在,是否会更有效?

编辑

关于属性包建议。经过深思熟虑后,这不是一个可行的解决方案。我“验证”接收器是否存在的原因是因为我们有附加到同一列表的第 3 方 Web 部件。在过去,这些实际上已经注销了我们的自定义接收器。在属性包中设置一个标志只会让我知道我已经验证过一次,但不会告诉我它们是否被其他人删除。

I am writing a web part against a list. The first thing I do in the web part is verify that my custom event receivers are registered on the list. If they are not, I register the programmatically.

I have noticed that if I try to register an event that is already registered, I get no errors and no “Extra” events are registered.

My question is: Would it be more efficient to just register the events each time the web part loads rather than iterating through each event in the event receiver list and doing compares to see if each of my event receivers are there?

Edit

About the Property bag suggestions. After thinking a bit more about it, this will not be a feasable solution. The reason that I am "verifying" that the receivers are there is because we have 3rd party webparts that are attached to the same list. These have, in the past, actually unregistered our custom receivers. Setting a flag in the property bag will just let me know that I have verified once, but won't tell me if they get removed by another.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一个人的夜不怕黑 2024-08-10 13:34:10

SharePoint 用于更新事件接收器集合的代码已被混淆,因此无法确定。我猜第一步是类似于您手动执行的检查。我倾向于选择最简单的方法,直到您发现性能是一个问题,在这种情况下,我会在列表的 RootFolder 的属性包上设置一个标志。

The code that SharePoint uses to update an event receiver collection is obfuscated, so there's no way to know for sure. I would guess that the first step is a check similar to what you are doing manually. I'm inclined to go with what's easiest until you identify that performance is an issue, in which case I would set a flag on the list's RootFolder's property bag.

悲凉≈ 2024-08-10 13:34:10

我不确定这是否是最好的方法。我见过一段代码,它的功能与您的要求类似。它的作用是,一旦添加了 EventHandler,它们就会在 SPWeb 属性包中存储一个标志。下次您只需检查属性包中是否有该标志(如果存在),则不要注册事件处理程序。有关属性包的更多信息,请参阅此链接。最后注意,您可能需要更多权限才能将属性包值设置为 SPWeb

I unsure if this is best approach. I have seen a code that does something similar to your requirement. What it does is that once the EventHandler are added they stored a flag in the SPWeb Property Bag. Next time you just check the Property bag for the flag if it is there dont register the eventhandler . Refer this link for more information about the property bag. Final note you might need more permission to set the property bag value to SPWeb

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文