如何触发 WebControls OnDispose 事件?

发布于 2024-12-01 09:59:41 字数 401 浏览 5 评论 0原文

我在我的 Page Dispose (覆盖但随后调用基本 Dispose)方法和我的 OnDispose 中设置了断点处理程序。

OnDispose 处理程序永远不会被调用,但 Page Dispose() 方法会被调用。

如果您无法调用处理程序,那么事件的意义何在?

这个问题类似于 这个问题

I have set breakpoints in my Page Dispose (which overrides but then calls the base Dispose) method and my OnDisposed handler.

The OnDisposed handler is never called, but the Page Dispose() method is.

If you can't call the handler, what's the point of having the event?

This question is similar to this question.

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

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

发布评论

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

评论(1

还不是爱你 2024-12-08 09:59:41

AutoEventWireup="true" 是调用 OnDispose 所需的内容。

AutoEventWireUp 页面属性意味着什么?

这是关于断点原因的一个很好的答案可能不会被击中。

何时触发 OnDispose

嗯,它们都是页面生命周期的一部分,但是问题在于
处置是它可能在页面生命周期结束后发生。
当对象引用超出范围时,它们将被扔进垃圾箱
收集器来处理,这可能会在页面完成后发生
完全完成了,这就是为什么你不能保证断点
进入他们。您可以明确强制处置,但事实并非如此
真的会对你的情况有所帮助,因为这些是服务器事件
反正。至少,我认为这是你想要的;一种拯救的方法
页面的客户端状态。

AutoEventWireup="true" is what you need for OnDisposed to be called.

What does AutoEventWireUp page property mean?

Here is a nice answer on why the breakpoint might not be hit.

When OnDisposed is triggered

Well they're all part of the page lifecycle, but the trouble with
disposal is that it might happen after the page lifecycle has ended.
When object reference go out of scope they are left to the garbage
collector to dispose of, and this can happen after the page has
completely finished, which is why you can't guarantee to breakpoint
into them. You could explicitly force the disposal, but it's not
really going to help your situation, since these are server events
anyway. At least, that's what I assume you want; a way to save the
client side state of the page.

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