Solved

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

Posted on 2009-07-05
3
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Accepted Solution

by:
Rahul Goel ITIL earned 400 total points
ID: 24782450
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
ID: 24782581
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
ID: 24783001
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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