.NETGURU
OnUnload event
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.csharp.

Post a new message to this list...

Viktor Popov
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.

Reply to this message...
 
    
SevDer
Viktor Popov wrote:
[Original message clipped]

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
Reply to this message...
 
    
Viktor Popov
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 ã.

Reply to this message...
 
    
SevDer
Viktor Popov wrote:

[Original message clipped]


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
Reply to this message...
 
    
Viktor Popov
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 ã.

Reply to this message...
 
    
SevDer
Viktor Popov wrote:

[Original message clipped]

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
Reply to this message...
 
 
System.EventArgs
System.EventHandler
System.Web.HttpContext
System.Web.Security.FormsAuthentication




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification