G
Guest
Hi
I am faced with the following problem: I have a page (let’s call this page page1.aspx) containing some TextBoxes and a hyperlink which opens another page (let’s call this page page2.aspx) as a popup using either window.open or window.showModalDialog. Since I want to warn the users of my application when they try to close page1.aspx and have changed the values in the meantime I thought about using the “onbeforeunload†event of the body of page1.aspx. Unfortunately this event also fires when the link gets clicked which is NOT intended by me.
Does anybody know how I can handle the close event of the page while being able to open links of my page? I know that it can somehow be done since I’ve seen this behaviour in MS CRM..
I tried the following
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="ATV2004.WebForm1"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><title>WebForm1</title><meta name="vs_snapToGrid" content="True"><meta name="vs_showGrid" content="True"><meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"><meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1"><meta name="vs_defaultClientScript" content="JavaScript"><meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"><script language="javascript"><!-
function SetPageToChanged()
document.Form1.txtChanged.value="1"
function CheckIfPageHasChanged()
if (document.Form1.txtChanged.value == "1"
event.returnValue = "\n\n--------------------------------------------------------------------------------------------------------------\nTo save your changes, click Cancel, and then click Save or Save and Close.\n\nTo close this record without saving your changes, click OK.\n--------------------------------------------------------------------------------------------------------------\n"
function PopUpMyWindow(){
window.showModalDialog('WebForm2.aspx',window,'Fullscreen=no; Scrollbars=no; Menubar=no; Locationbar=no; Resizable=no; Status=no; dialogWidth=450px; dialogHeight=400px;')
//--></script></HEAD><body onbeforeunload="CheckIfPageHasChanged()"><form id="Form1" method="post" runat="server">  
<input type="hidden" id="txtChanged"><a href="javascriptopUpMyWindow()">This is a link.</a><input type="text" onBlur="JavaScript:SetPageToChanged();"></form></body></HTML
Thank you for your help
Daniel Walzenbac
I am faced with the following problem: I have a page (let’s call this page page1.aspx) containing some TextBoxes and a hyperlink which opens another page (let’s call this page page2.aspx) as a popup using either window.open or window.showModalDialog. Since I want to warn the users of my application when they try to close page1.aspx and have changed the values in the meantime I thought about using the “onbeforeunload†event of the body of page1.aspx. Unfortunately this event also fires when the link gets clicked which is NOT intended by me.
Does anybody know how I can handle the close event of the page while being able to open links of my page? I know that it can somehow be done since I’ve seen this behaviour in MS CRM..
I tried the following
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="ATV2004.WebForm1"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML><HEAD><title>WebForm1</title><meta name="vs_snapToGrid" content="True"><meta name="vs_showGrid" content="True"><meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"><meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1"><meta name="vs_defaultClientScript" content="JavaScript"><meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"><script language="javascript"><!-
function SetPageToChanged()
document.Form1.txtChanged.value="1"
function CheckIfPageHasChanged()
if (document.Form1.txtChanged.value == "1"
event.returnValue = "\n\n--------------------------------------------------------------------------------------------------------------\nTo save your changes, click Cancel, and then click Save or Save and Close.\n\nTo close this record without saving your changes, click OK.\n--------------------------------------------------------------------------------------------------------------\n"
function PopUpMyWindow(){
window.showModalDialog('WebForm2.aspx',window,'Fullscreen=no; Scrollbars=no; Menubar=no; Locationbar=no; Resizable=no; Status=no; dialogWidth=450px; dialogHeight=400px;')
//--></script></HEAD><body onbeforeunload="CheckIfPageHasChanged()"><form id="Form1" method="post" runat="server">  
<input type="hidden" id="txtChanged"><a href="javascriptopUpMyWindow()">This is a link.</a><input type="text" onBlur="JavaScript:SetPageToChanged();"></form></body></HTML
Thank you for your help
Daniel Walzenbac