Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-07-05
3
Medium Priority
?
187 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 ITIL earned 1600 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 400 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

963 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