Interviews2 answers
how to update a database value while closing the asp.net page? (unload event is nt working)
2 Answers
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)
{
}
}
}
sunil kumarPosted Sep 26, 2008, 2:32 AM EDT
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
Bechir BejaouiPosted Sep 25, 2008, 8:36 AM EDT
