简体   繁体   English

关闭弹出窗口时如何删除会话变量?

[英]How to remove sessionvariable when closing popup window?

I have a popup window where i store an a arraylist in sessionvariable, when clicking on closebutton (the X in the right top corner) or the cmd input button in the form i want to remove the sessionvariable containing my arraylist. 我有一个弹出窗口,当我单击关闭按钮(右上角的X)或窗体中的cmd输入按钮时,我要在其中存储一个数组列表,我想删除包含我的数组列表的sessionvariable。 How can i do this? 我怎样才能做到这一点?

The popup window is currently closed by a javascript: 弹出窗口当前被javascript关闭:

function cmdClose_onclick() {
    self.close();
}

Session variables are stored on the server, so you need to inform the server that something happened on the client, and call an appropriate function to remove the session variable. 会话变量存储在服务器上,因此您需要通知服务器客户端上发生了某些事情,并调用适当的函数来删除会话变量。

There are a couple ways you could do this. 您可以通过几种方法来执行此操作。

  1. You could make an AJAX request to a page, a page method or a custom HTTPHandler . 您可以向页面,页面方法或自定义HTTPHandler发出AJAX请求。 If you write a custom .ashx file, you could simply make a request to it's URL and have it delete the session variable. 如果编写自定义.ashx文件,则只需向其URL请求,然后删除会话变量即可。

  2. Make your page do a postback when you close the window. 关闭窗口时,使页面进行回发。 You can manually trigger postbacks by calling __doPostBack() in javascript, or just executing a button click or form submit. 您可以通过在javascript中调用__doPostBack()来手动触发回发,或者仅执行按钮单击或表单提交。

I'd go with option #1 if you can. 如果可以的话,我会选择选项#1。

我建议让javascript对WebMethod进行AJAX调用,以清除会话变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM