English 中文(简体)
c# page_unloadfire among after page_load
原标题:c# page_unload firing together with after page_load
  • 时间:2012-05-09 17:34:53
  •  标签:
  • c#
  • asp.net

因此,在用户关闭浏览器时,我想删除一些文件。

使用<代码>的Im 方法如下:

   protected override void OnUnload(EventArgs e)
    {
        base.OnUnload(e);
        string[] uploadedFiles = Directory.GetFiles(Server.MapPath("~/testPdfIn"));
        foreach (string uploaded in uploadedFiles)
        {
            File.Delete(uploaded);
        }
    }

页: 1 这种方法将仅仅在页数之后发射,在用户甚至不关闭浏览器的情况下,将文件夹碎。

是否有办法阻止<代码>page_unload 从装载后发射的权利到用户关闭浏览器时发射?

最佳回答

更能发现浏览器的近事,而使用jax的电机服务器的辅助功能则不为你服务。

<script type="text/javascript">
$(function () {
    $(window).unload(function () {

   jQuery.ajax({ url: "http://localhost:49591/filedelete.aspx", async: false });
      });
});
</script>
问题回答

...... 如何做工作,如果你想在网页上做一些事情的话,则window.on beforeunload

Page.Unload does not work how you think it works. Page.Unload is fired at the end of the Page life-cycle, not when the browser is closed:

The Unload event is raised after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and cleanup is performed.

密码背后的方法是服务器,而浏览器被关闭是客户活动。

<代码>Page_Unload与浏览器关闭无关。 一旦所有页数/页数全部填满,即发生卸载事件。

您应考虑将你的档案删除代码列入session_end。 页: 1





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签