473,804 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OnUnload event

Hi,
Iwould like to do that. Is it possible because I can't do it?
in test.aspx file:
<body onunload="signo ut()">

in test aspx.cs
:
void private signout()
{
HttpContext.Cur rent.Cache.Remo ve(Session["usrName"].ToString());
Session["user"]=null;
Session["usrName"]=null;
FormsAuthentica tion.SignOut();
}

Is it possible to use C# function in onunload event.
Please could you tell me hoe to implement this. I should use the code in
signout() function when onunload event occures.

Thank you,

Viktor
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10.9.2004 a.
Nov 16 '05 #1
5 5021
Viktor Popov wrote:
Hi,
Iwould like to do that. Is it possible because I can't do it?
in test.aspx file:
<body onunload="signo ut()">

in test aspx.cs
:
void private signout()
{
HttpContext.Cur rent.Cache.Remo ve(Session["usrName"].ToString());
Session["user"]=null;
Session["usrName"]=null;
FormsAuthentica tion.SignOut();
}

Is it possible to use C# function in onunload event.
Please could you tell me hoe to implement this. I should use the code in
signout() function when onunload event occures.

Thank you,

Viktor
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10.9.2004 a.


Viktor,

You are mixing server code with client code.
QUTOE
<body onunload="signo ut()">
UNQUOTE

This signout() method will run in the client script not code behind.

If you want it in code behind then you can open the hidden "Web Form
Designer generated code" region and in "InitializeComp onent()" method
specifically define "this.Unloa d += new EventHandler(re sBox_Unload);"
then if you do the tabbig that VS.NET suggests, it will also generate
the unload method for you and you can type in your code.

I hope this helps.
--

SevDer
http://www.sevder.com
Nov 16 '05 #2
Hi, Thanks for the reply!
I would like to run this code on the client side:
void private signout()
{
HttpContext.Cur rent.Cache.Remo ve(Session["usrName"].ToString());
Session["user"]=null;
Session["usrName"]=null;
FormsAuthentica tion.SignOut();
}

How could be accomplished that?
I don't know exactly where should be written this function.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10.9.2004 ã.
Nov 16 '05 #3
Viktor Popov wrote:
Hi, Thanks for the reply!
I would like to run this code on the client side:
void private signout()
{
HttpContext.Cur rent.Cache.Remo ve(Session["usrName"].ToString());
Session["user"]=null;
Session["usrName"]=null;
FormsAuthentica tion.SignOut();
}

How could be accomplished that?
I don't know exactly where should be written this function.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10.9.2004 ã.

Viktor,

You can't do that.
1. You need to use JavaScript or VBScript on client site
2. Codebehind namespaces, sessions etc. are server objects not client.

Basically what you can do is in onunload event, call a client side
function signout, that will pop-up a window and in this window you will
just run the server side (codebehind) logic (the one you defined) and in
this pop-up windows onload event close that window with window.close().

However, as you see, this will not work all the time.

On the other hand,
1. I don't think you should keep user name in Cache object (Cache is
like Application variable, shared by everything on that application)
2. When the user closes window, his/her session will be killed anyway
and they cannot reached this session again, unless they didn't close all
related pages.

I hope this helps/
--

SevDer
http://www.sevder.com
Nov 16 '05 #4
Thanks again,
I keep username in Cache because I would like to prevent multiple logins. Do
you know how to do that in other way? In my case everything is OK if the
user logs off from the server side button. When he/she closes the window
from X-button , she/he must wait until the session ends. That's the problem
which I should do. Could you give me an advice how to manage with that?

Thank you!
Viktor

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10.9.2004 ã.
Nov 16 '05 #5
Viktor Popov wrote:
Thanks again,
I keep username in Cache because I would like to prevent multiple logins. Do
you know how to do that in other way? In my case everything is OK if the
user logs off from the server side button. When he/she closes the window
from X-button , she/he must wait until the session ends. That's the problem
which I should do. Could you give me an advice how to manage with that?

Thank you!
Viktor

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.760 / Virus Database: 509 - Release Date: 10.9.2004 ã.


Viktor,

I think you can also have a look at the following method

protected void Session_End(Obj ect sender, EventArgs e)
{

}

which is located in global.asa

As you see this method happens, when the session ends. It may help.

Also, on client onunload event, you may really try to open a pop-up
window which will signout the user from the server side and then close
itself.
--

SevDer
http://www.sevder.com
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8571
by: Andoni | last post by:
Hi, I am only writing for IE 5.5+ so no need for compatibility at all ;-) I am trying to get my users to logoff which they finish on a particular page. This is no problem (or should be no problem) as I can just put a location.replace('http://www.mysite.com/html/logoff.jsp'); into the onUnload event of the page they always finish on. This should fire when they click the X in the corner (my app. is in a popup window) instead of hitting...
3
6972
by: Laurent | last post by:
I am trying to use the onunload event to know when the user closes a popup by receiving a request on the web server. I have a main page from where the user opens a popup. What I want is when the user closes the popup, it sends a request to my web server (GoAhead) using the onunload event, then closes the popup. For the moment, this what i have: when the user closes the popup, I use the onunload event to open a different popup (by this...
5
1590
by: feng | last post by:
I want to use onunload to capture user's action when he clicks on the "x" button to close the browser. Here is how I do this: <SCRIPT FOR="window" EVENT="onunload"> myScript(); </SCRIPT> While myScript() does get called when "x" gets clicked, it is also get called when the user leaves the current page and navigate to another page within our web application.
3
5879
by: =B= | last post by:
Hi all, I was wondering if anyone has had any luck with trapping the <BODY> onUnload() event in ASP.NET? The thing is, I'm writing code for an Intranet site. The code makes a call to a third-party component (think of it as a lock) when the page loads. Now the OK and Cancel server buttons I can handle and use to release the lock as required. But previously in classic ASP I had been trapping the user hitting the close 'x' button by...
1
3920
by: Angel | last post by:
I am trying to capture when the user clicks the X button on the ie window. I have used the onunload for the window event, but there is a problem. I put javascript code for this event and when the form performs a postback on the page, the onunload event gets triggered eventhough I am still on the same page and the user did not click the 'X' button. In other words, the onunload event is triggered when you are performing a postback to the...
1
5328
by: Laurent Bugnion | last post by:
Hi, I am trying to programatically add an "onunload" event handler to the "body" tag of an ASPX page. I am doing this from a Custom Control located on this page. To do this, I added "runat=server" to the body tag, which provides me access to it in the code-behind through a HtmlControl. I can then manipulate the Attributes collection, which is what I needed. So far so good.
7
2924
by: tgh003 | last post by:
I have been at this for hours now. Pulling my hair out. I have a standard php page that has an onunload event on it. The onunload event sends a xmlhttprequest that triggers a database update, for simplicity lets say it updates a table: UPDATE testtable SET testfield = '".$_GET."' where id = 1 This works just fine. Then the next page you navigate to is supposed to call the testfield
5
2718
by: jackchang1 | last post by:
I have an application that will submit the form when the page is closed (through onunload event), and it works fine in IE6. But it doesn't work in FireFox, and no data is sent. It seems to me that FireFox doesn't let the onunload event ends before the window is closed. Or is it an form submit issue in the onunload event? Thanks!
0
10595
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10088
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7633
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.