Solved

onbeforeunload with condition

Posted on 2006-07-23
3
560 Views
Last Modified: 2008-02-01
In ASP.NET 2.0 with C#
I want to use the command onbeforeunload in order to check if the user presses the close button:
<body onbeforeunload="return ' '">
but this command shows the message each time the page is refreshed.
Can I give a condition that it will not appear in each refresh?
for example the following code check if the value in the page was changed and only if true the onbeforeunload
will active.
I need to do it in .NET and check if the values in the formview in the page were changed and not in each
refresh of the page.
How do I do it?

<head>
<script>
var oldVal = "";
function saveValues()
{   oldVal = document.myForm.tester.value;}

function checkChanges()
{  if ( oldVal != document.myForm.tester.value )
   { return 'Are you sure you wish to exit dude?';}}

</script>
</head>
<BODY onload="saveValues();" onbeforeunload="return checkChanges();">
<form name="myForm">
<input type="text" name="tester">
</form>
</body>
0
Comment
Question by:ANAT2403
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 17162961
Here is an option:

-----------------------------------
On Any Forms Want to detect
-----------------------------------
detect close ie X button ( close window)
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=4878&lngWId=10

<HEAD>
<SCRIPT language="JavaScript" >
function detactCloseWin() {
    var top=self.screenTop;
     if (top>9000) {
        window.open("closeWindow.aspx","_blank","fullscreen=0,width=0,height=0,
                             scrollbars=0,toolbar=0,menubar=0,status=0");
    }
}
</SCRIPT>
</HEAD>
<BODY onunload="detactCloseWin();" MS_POSITIONING="GridLayout">

-------------------
On new window
-------------------
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
     General.chat.Delete_ActiveUser()
     Response.Write("<script language='javascript'> { window.close();}</script>")
End Sub

Bob
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 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