Solved

Need to run the update script when the user exits the page - ASP.NET (C#)

Posted on 2009-07-05
3
180 Views
Last Modified: 2012-05-07
Hi,

Need to do two things:

1. Run one update statement when user comes on a particular page
2. Run another update when user exists that page.

Sr.no 1 can be done on Page_Load event.

For Srno.2,  User can exit the page in two ways:
(a) Closing the browser
(b) Clicking the link of other page.

How do I run the update when the user exists the page through above two cases (i.e. a & b)?

Thanks!

0
Comment
Question by:meetpd
3 Comments
 
LVL 9

Accepted Solution

by:
Rahul Goel earned 400 total points
Comment Utility
See, both approaches can be achieved using javascript event handlers. and make a ajax call to the server
 
Here is the code for trapping windows close

<html>

<head>

<title>Detecting browser close in IE</title>
 
 

<script type="text/javascript">
 

var myclose = false;
 

function ConfirmClose()

{

if (event.clientY < 0)

{

event.returnValue = 'Any message you want';
 

setTimeout('myclose=false',100);

myclose=true;

}

}
 

function HandleOnClose()

{

if (myclose==true) alert("Window is closed");

}
 

</script>

</head>
 
 

<body onbeforeunload="ConfirmClose()" onunload="HandleOnClose()">
 

<h4>Close browser!</h4>
 

</body>

</html> 

Open in new window

0
 

Author Comment

by:meetpd
Comment Utility
Can I put an sql update statement in this? How?

Sorry for the silly question, but I am a newbie.
0
 
LVL 3

Assisted Solution

by:DreamsTech
DreamsTech earned 100 total points
Comment Utility
U can call any evnet from the javascript function:

Put a Attribute ScriptMethod: on the Method to be called
 and call this from javascript call

 PageMethods.UpdateQuerry();

in ur cs file

[ScriptMethod:]
UpdateQuerry()
{

  //Update Query
}
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now