Solved

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

Posted on 2009-07-05
3
181 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Code works but I need to redo it and assign values to Model 7 33
Class object 2 27
Greetings C# program 17 57
C# Single Form 8 28
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

13 Experts available now in Live!

Get 1:1 Help Now