检测用户何时在 Page_Load 事件中离开页面
当用户离开页面时,它会再次触发 Page_Load 事件。我如何在 code_behind 中知道这种情况正在发生,以便可以避免运行自定义函数,因为 Page_Load 中的代码在离开页面时实际上并不需要运行?
When a user leaves a page it fires of the Page_Load event again. How can I tell in code_behind that this is happening so in can avoid running the custom functions as the code in the Page_Load does not really need to be ran when leaving the page?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
离开页面是什么意思?关闭浏览器或单击浏览器上的“后退”按钮?或者转移到另一个页面?
Page_Load
方法在加载页面或同一页面上发生回发时触发,但不会离开该页面。在开始任何操作之前,您可以(并且应该)确保客户端仍处于连接状态并使用 HttpResponse.IsClientConnected 属性。
当满足以下条件时,IsClientConnected 属性返回 false:
http://msdn.microsoft.com/en-us /library/system.web.httpresponse.isclientconnected.aspx
编辑
切换选项卡通常会触发正常的回发,要检测它,您应该使用:
What do you mean by leaving a Page? Closing the browser or clicking Back button on browser? Or moving to another Page?
Page_Load
method is fired when on Loading Page or when Postback occurs on the same Page, but not leaving it.Before you start any operations, you can (and you should) ensure that client is still connected and use
HttpResponse.IsClientConnected
property.The IsClientConnected property returns false when the following conditions are true:
http://msdn.microsoft.com/en-us/library/system.web.httpresponse.isclientconnected.aspx
EDIT
Switching tabs usually fires normal Postback, to detect it you should use:
如果我正确理解这个问题,您正在寻找 IsPostBack 属性:
If I understand the question correctly, you're looking for the IsPostBack property: