473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

OnUnload event

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

in test aspx.cs
:
void private signout()
{
HttpContext.Current.Cache.Remove(Session["usrName"].ToString());
Session["user"]=null;
Session["usrName"]=null;
FormsAuthentication.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 5005
Viktor Popov wrote:
Hi,
Iwould like to do that. Is it possible because I can't do it?
in test.aspx file:
<body onunload="signout()">

in test aspx.cs
:
void private signout()
{
HttpContext.Current.Cache.Remove(Session["usrName"].ToString());
Session["user"]=null;
Session["usrName"]=null;
FormsAuthentication.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="signout()">
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 "InitializeComponent()" method
specifically define "this.Unload += new EventHandler(resBox_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.Current.Cache.Remove(Session["usrName"].ToString());
Session["user"]=null;
Session["usrName"]=null;
FormsAuthentication.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.Current.Cache.Remove(Session["usrName"].ToString());
Session["user"]=null;
Session["usrName"]=null;
FormsAuthentication.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(Object 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
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...
3
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...
5
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> ...
3
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...
1
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...
1
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...
7
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,...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.