Reputation: 6829
I have link at my asp.net page. I need to store some data in session before user goes to that link location. Is there any event that I can catch when user going to leave that page?
PS I can't store that data when user click on link. I need event on leaving page.
Upvotes: 2
Views: 2591
Reputation: 3113
Your best hope is to use Javascript events.
You can use the window.onunload or window.onbeforeunload to either fire of an AJAX request or warn the user to save their work before continuing.
Obviously, both of these events are browser dependent and rely on Javascript being switched on.
Upvotes: 0
Reputation: 41490
Try using JavaScript to intercept the user before page exit and then in the JS function send an Ajax post to the ASP.net page with the logging details (which would then be put into the user's session object).
Upvotes: 1
Reputation: 22580
The way the web works is stateless. The server is not aware of your user leaving a page. It is only aware of a new request that is coming in, which would happen after the user clicked on a certain link.
If you wanted to store data in the session before that link was clicked, you would have to store it in the session on the previous request when you were generating the page containing the link.
Upvotes: 4