2
Reply

how to update a database value while closing the asp.net page? (unload event is nt working)

Jai Prakash

Jai Prakash

16y
4.1k
0
Reply

    hi you can try this code: // JScript File var myclose = false; var objLogout = null; function ConfirmClose() { if (event.clientY < 0) { event.returnValue = 'Are you sure to close the browser?'; setTimeout('myclose=false',100); myclose=true; } } function LogoutUser() { if (myclose==true) { Logout(); } } function Logout() { try { objLogout = new XMLHttpRequest(); } catch(ex) { try { objLogout=new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { objLogout=new ActiveXObject("Microsoft.XMLHTTP"); } catch(e1) { objLogout=null; } } } objLogout.onreadystatechange=Process_Response_Logout; objLogout.open("GET","BrowserCloseLogout.aspx",true); objLogout.send(null); return false; } function Process_Response_Logout() { if(objLogout.readyState == 4) { if(objLogout.status == 200) { } } }

    Implement the IDisposable interface class ClassName:IDisposable { ...... IDisposable.Dispose() { yourConnection.Close(); } } or you can use string Connectionstring = ""; //TO DO precise your connection string between cotes using(xxxConnection cn = new Connection(ConnectionString)) { //TO DO :Put your code here } Once the connection is not used it will be closed automatically