Asp.net中当页面关闭时执行代码

2025-03-01 12:25:04
推荐回答(3个)
回答1:

可以在Page_Unload事件操作.
IIS卸载页面,并把页面传送给浏览器时,会自动执行Page_Unload()。

Page_Unload不好用.修改.
那试试用Javascript调用.C#的代码吧.
----------.aspx:
----Javascript:


----Html:

------------------------------------

----------.cs:
----C#
public string CloseWindow()
{
//...后台操作代码.
return "";
}

回答2:

Page_Unload()

跟Page_load()方法参数一样,只不过事件效果相反,前面是页面卸载(就是关闭的意思),后面的是加载的时候激发

回答3:

Response.End()