Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 8th, 2005, 03:24 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I don't know. I can imagine is a security feature from the browser, preventing you from returning false from this function.

That's why I said it would be messy in my first post.... ;)

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old November 13th, 2005, 02:01 PM
Registered User
 
Join Date: Nov 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to javajames
Default

This would better fit in a JavaScript forum, but I wasn't sure if you found a solution yet, so I thought I would put in my 2 cents.

The value returned from ConfirmClose when overriding the onbeforeunload is a string that will appear in the default browser confirm popup.

This should work:

var isNotesNeedToBeSaved = false; //true if notes need to be saved
<body onbeforeunload="return isNotesNeedToBeSaved ? 'Notes need to be saved.' : true">

If for any reason you don't have access to the body tag (as was my case, it is generated from the server before my code) you can insert a script within the body element:
<script ...>
var isNotesNeedToBeSaved = false; //true if notes need to be saved
document.getElementsByTagName("BODY")[0].onbeforeunload = ConfirmClose;

function ConfirmClose()
{
  if( isNotesNeedToBeSaved )
    return "Notes need to be saved.";
  else
    document.getElementsByTagName("BODY")[0].onbeforeunload = true;
}

I only tried this in IE.





Similar Threads
Thread Thread Starter Forum Replies Last Post
sub Routine problem NitinJoshi General .NET 1 January 5th, 2005 04:10 AM
How to pass variables from Aspx page to Asp Page jayaraj Classic ASP Basics 2 May 23rd, 2004 06:56 AM
How to pass the variables in Aspx page to Asp Page jayaraj ASP.NET 1.0 and 1.1 Basics 3 May 23rd, 2004 06:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.