Thanks shweta for response but i have reffered this link also... but still i have not got solution in that link...
Plater had the right idea in suggesting the OnUnload JavaScript Event. The problem is when that happens the page is already unloaded and you can't make a call to the server.
Instead you should use the OnBeforeUnload JavaScript event to make a call back to the server and log out the user.
-
window.onbeforeunload = function()
-
{
-
//here you make your call to the aspx page to log out the user
-
//make sure you don't return anything or else the user will be prompted to make a decision as to whether or not they want to actually leave the page....
-
}
-
This will log out the user as soon as the close the window or leave the webpage.
Just be aware that all of your full page post backs to the server will cause the page to be unloaded. This means that you should probably add another JavaScript function to "register" the controls for valid postbacks.
Eg
-
var _validPostback = false;
-
function RegisterValidPostBack()
-
{ _validPostback=true;}
-
window.onbeforeunload = function()
-
{ if(_validPostback==true)
-
{
-
//here you make your call to the aspx page to log out the user
-
//make sure you don't return anything or else the user will be prompted to make a decision as to whether or not they want to actually leave the page....
-
}
-
}
-
In your Server Side code you will have to add the onclick JavaScript event to each control that posts back..
eg
-
myButton.Attributes.Add("onclick","RegisterValidPostBack();")
-
-Frinny