473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Asp .Net : Detect browser closing

rrocket
116 100+
I am trying to capture the fields in a form if the user navigates away from the page to see if there is a trend in what boxes are being left blank. I have tried to put an unload event in, but I cannot get it to fire.

Does anyone know how I could add a trigger for when a person closes the browser or navigates away from the page? I have been looking all day, but have not been able to come up with anything that works. I am using a master page so putting an unload event in the body does not work for me.

Thanks :)
Nov 26 '07 #1
7 9824
Shashi Sadasivan
1,435 Expert 1GB
Wont you have to wait for the user to fill in the form and submit?

If the user closes the browser, then they either (have a phone call)
the computer hung and rebooted itself (or did not even reboot)

The user does not want to continue any further.

I think you should look at when the user completes the form and submits it rather than checking if the browser was closed or not. (which may be possible using javascript - -not sure)
Nov 27 '07 #2
mzmishra
390 Expert 256MB
on javascript onbeforeunload and onunload events are triggered when the window closes, also during normal page navigation.

Have you tried any of these?
Nov 27 '07 #3
rrocket
116 100+
I am using a masterpage so using the javascript is a no go in the body tag (as far as I know) since I do not need it to fire on all pages.

I tried using something like this:
Expand|Select|Wrap|Line Numbers
  1. ClientScript.RegisterClientScriptBlock(this.GetType(), "onUnload", "javascript:alert();", true);
in the codebehind, but it fires as soon as the page is loaded. If you know how to get an unload event to fire from the codebehind please fill me in since nothing I have tried has worked... Here is one of the attempts:
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Unload(object sender, EventArgs e)
  2.     {
  3.         ClientScript.RegisterClientScriptBlock(this.GetType(), "onUnload", "javascript:alert();", true);
  4.     }
I do have a submit button, but I am curious to see what fields are left blank when they leave the page without hitting submit.
Nov 27 '07 #4
rrocket
116 100+
Anyone have anymore ideas?
Nov 28 '07 #5
rrocket
116 100+
I figured it out...

I put this in the codebehind:
Expand|Select|Wrap|Line Numbers
  1.  HtmlGenericControl body = (HtmlGenericControl)Master.FindControl("mBody");
  2.         body.Attributes.Add("onunload", "checker()");
  3.  
This in the Masterpage body tag:
Expand|Select|Wrap|Line Numbers
  1. <body id="mBody" runat="server">
  2.  
and finally the function in the masterpage:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     function checker()
  3.     {
  4.         alert("Working?");
  5.     }
  6.     </script>
Nov 29 '07 #6
rrocket
116 100+
Well, I at least got a popup to come up, but I cannot get anything else to work on the js side. When I try to pull information from a textbox with document.getElementbyID('anything').value it gives me an error saying their are no properties.

I tried using:
Expand|Select|Wrap|Line Numbers
  1. protected void OnUnloader(object sender, EventArgs e)
  2. {
  3.     Response.Redirect("http://www.google.com");
  4. //This is just for testing, if I can get this to fire I will put my own logic in to pull the values for fields that have data in them.
  5. }
in the codebehind and
Expand|Select|Wrap|Line Numbers
  1. OnUnload="OnUnloader()"
on the design page (attached to one of the textboxes), but I get this error - CS1501: No overload for method 'OnUnloader' takes '0' arguments

Does anyone have any ideas on how to get this to work? My goal is to obtain the information entered into the form when the submit button is not clicked. This will give me a better idea of what fields are left blank and more insight into problem areas that are causing clients not to finish the request form.
Dec 3 '07 #7
rrocket
116 100+
This is what I am trying to get to work now... The stored procedure fires and loads info to the DB, but it does it on page load not page unload. Any advice would be appreciated.
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Init(object sender, EventArgs e)
  2.     {
  3.         this.Unload += new EventHandler(QuickQuote_Unload);
  4.     }
  5.  protected void QuickQuote_Unload(object sender, EventArgs e)
  6.     {
  7.       (Stored Procedure)
  8. }
  9.  
I tried using:
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Unload(object sender, EventArgs e)
  2.     {
  3.         this.Unload += new EventHandler(QuickQuote_Unload);
  4.     }
  5.  
But nothing happend at all.
Dec 3 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Derek | last post by:
Hello: I want to capture the event when a browser is closing, to give to the user the posibility of close or no this browser. When the browser is closing, this show a confirm window with two...
1
by: Matt | last post by:
When the page is refresh, it will first call window_unload() and then call window_load(). The problem is I window_unload() is invoked when the user click close button, or right top icon close...
1
by: Chirag Malvi | last post by:
hello all, I am developing the web application using ASP.net and VS.2003 IDE. here is the situation which i want to implement. 1) User is browsing some webform. I want to trap this event....
6
by: hb | last post by:
Hi, Would you please tell me how to detect if the client's browser is closed? I need such event to trigger a database modification. Thank you hb
2
by: NWx | last post by:
Hi, I have the following question: I have an app that uses user login/logout to identify users When user logon, I register logon time in a session variable When user logoff using the logout...
12
by: Patrick Dugan | last post by:
I have an vb.net application that is a module that uses a "application.run" in the sub main to start. There is no form involved (just a system tray icon) How can you detect when the application...
7
by: tarun.kataria | last post by:
Hi All, Is there any way to detect that the user is trying to Xout the browser window instead of hitting a button. Because in my application I want to make it sure that they dont do it either...
2
by: sylvain | last post by:
is there a simple way to detect a web window closing when the user hit the X of the browser ? I want to display a message to the user when he goes out of my web page. I try to detect it by using...
1
by: nebulus | last post by:
I'm working on a web app that under normal circumstances will be happy with the Session_OnEnd event, but when a user leaves a page by closing the browser by either Alt+F4 or just hitting the "X",...
18
by: sebastian | last post by:
Can this be done without client-side scripting? I thought sessions might be the answer but after some testing found that sometimes the old session data remained even after the user left the site...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.