[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

Can the user response to the IE7 prompt when closing a window be captured?

Hello Experts,
Is there a way to trap the user response to the prompt IE7 uses when closing a window?  In an asp.net application, code runs when a button is clicked.  This button assumes the user presses "Yes"  ( I want to close the window)  If the user presses "No", I need to be able to do something else.
Howard Katz
Howard Katz
  • 2
1 Solution
Sachintana DissanayakeSenior Web DeveloperCommented:
Did you try with onunload or onbeforeunload event.

<script type="text/javascript">
function doUnload()
   //do form submission to perform an operation

< body onunload="doUnload()">
< /body>
Howard KatzDatabase Report DeveloperAuthor Commented:
Thanks for your quick response....

Here is the situation.  In an asp.net 2.0 application, on a master page there is a asp:button control.  The onClick="btnReleaseRecord_Click"

(see code snippet)

what I would like is that if the user selects No, then the code below
ScriptManager.RegisterClientScriptBlock....NewGuid().ToString, "window.close()", True)

does not fire.


Protected Sub btnReleaseRecord_Click(..., ...)
   ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(),        Guid.NewGuid().ToString, "window.close()", True)
  If Session("OwnerExiting") = "yes" Then
     Application.Remove(Session("QuoteNumber") & "User")
  End If
  Dim ow = Session("OwnerExiting")
  Session("OwnerExiting") = "yes"
 End Sub

Open in new window

Sachintana DissanayakeSenior Web DeveloperCommented:
Just put alert instead of window.close() and check whether its registering the javascript properly.
     ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), Guid.NewGuid().ToString, "javascript:alert('test alert');", True)

I recommend you to move the javascript content (even single line) to a function and call the function above.
Forced accept.

EE Admin

Featured Post

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now