Session time out
-
HI Some prob in my project is that, I want to call session_End after browser window is close ... How it is possible Thanx.... yogesh M
There is no fail-safe way to do that. You can catch the onunload event in the browser, and open a new window that will do the logout. This will of course not work if the user already is disconnected, has disabled javascript or has a popup blocker that prevents the window to open. --- b { font-weight: normal; }
-
HI Some prob in my project is that, I want to call session_End after browser window is close ... How it is possible Thanx.... yogesh M
Hi Yogesh M, The onbeforeUnload event calls the HandleOnClose function which checks if the variable currentElement has a value or not. </head> <body onbeforeunload="HandleOnClose(event)"> <form id="form1" runat="server"> The JavaScript function HandleOnClose checks for this attribute tag of the currentElement object. If currentElement is null or the value of the tag attribute of currentElement is not DonotCallSaveonLoad, then it calls the function FunctiontoCallSaveData; otherwise, the save functionality on the code-behind is called. var keyPressed = ""; //Variable to store which key was pressed var dataChanged = false; var currentElement = ""; //Function called when the browser is closed. function HandleOnClose(evt) { if (currentElement == "" || (!(currentElement.getAttribute("tag")=="DonotCallCloseonLoad"))){ var objconfirm = confirm("Would you like to close the page?") if (objconfirm == true) { FunctiontoDoSomething(); } } } The implementation of the function FunctiontoCallSaveData is the same as previously sent, which is as follows: <script> //Function to submit the form and call the Page_load function on server side. function FunctiontoCallSaveData() { document.getElementById("<%=hdtoSaveData.ClientID %>").value="PageClosed"; document.form1.submit(); } </script> form.submit will in turn call Page_Load in which the Save functionality can be called. Error handling can also be performed for this functionality. Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Try If Not IsPostBack Then LoadControls() End If If hdtoSaveData.Value = "PageClosed" Then Session.Abandon(); End If Catch ex As Exception hdError.Value = ex.Message ExceptionPolicy.HandleException(ex, "SamplePolicy") GetDatafromTable("Error") End Try End Sub
Rajendra Prasad Panchati .Net/Sharepoint Software Engineer. Hyderabad.