How to prevent a changed page from beeing closed???

  • Thread starter Thread starter Guest
  • Start date Start date
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">&nbsp;&nbsp;&nbsp

<input type="hidden" id="txtChanged"><a href="javascript:PopUpMyWindow()">This is a link.</a><input type="text" onBlur="JavaScript:SetPageToChanged();"></form></body></HTML

Thank you for your help
Daniel Walzenbac
 
Hi Daniel,

You should post this question in the Internet Explorer client development
groups. They can assist you with writing client-side code.

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.


--------------------
Thread-Topic: How to prevent a changed page from beeing closed???
thread-index: AcPvHj7cM4M4jlZyTGCzRjdtRTekVg==
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
From: "=?Utf-8?B?RGFuaWVsIFdhbHplbmJhY2g=?="
Subject: How to prevent a changed page from beeing closed???
Date: Mon, 9 Feb 2004 07:06:07 -0800
Lines: 32
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 8bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.aspnet
Path: cpmsftngxa07.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:208562
NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

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">&nbsp;&nbsp;&nbsp;

<input type="hidden" id="txtChanged"><a
href="javascript:PopUpMyWindow()">This is a link.</a><input type="text"
onBlur="JavaScript:SetPageToChanged();"></form></body></HTML>


Thank you for your help!
Daniel Walzenbach
 
Jim,

would you mind telling me exactly which group you mean?
microsoft.public.internetexplorer.ie55.programming ???

Thank you a lot!

Daniel


Jim Cheshire said:
Hi Daniel,

You should post this question in the Internet Explorer client development
groups. They can assist you with writing client-side code.

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
(e-mail address removed)

This post is provided as-is with no warranties and confers no rights.


--------------------
Thread-Topic: How to prevent a changed page from beeing closed???
thread-index: AcPvHj7cM4M4jlZyTGCzRjdtRTekVg==
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
From: "=?Utf-8?B?RGFuaWVsIFdhbHplbmJhY2g=?="
Subject: How to prevent a changed page from beeing closed???
Date: Mon, 9 Feb 2004 07:06:07 -0800
Lines: 32
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="Utf-8"
Content-Transfer-Encoding: 8bit
X-Newsreader: Microsoft CDO for Windows 2000
Content-Class: urn:content-classes:message
Importance: normal
Priority: normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
Newsgroups: microsoft.public.dotnet.framework.aspnet
Path: cpmsftngxa07.phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:208562
NNTP-Posting-Host: tk2msftcmty1.phx.gbl 10.40.1.180
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Hi,

I am faced with the following problem: I have a page (letâ?Ts call this
page page1.aspx) containing some TextBoxes and a hyperlink which opens
another page (letâ?Ts 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 â?oonbeforeunloadâ? 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â?Tve 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">&nbsp;&nbsp;&nbsp;

<input type="hidden" id="txtChanged"><a
href="javascript:PopUpMyWindow()">This is a link.</a><input type="text"
onBlur="JavaScript:SetPageToChanged();"></form></body></HTML>


Thank you for your help!
Daniel Walzenbach
 
No, I haven't seen Microsoft CRM, but IE's security model does not allow
"untrusted" Javascript (e.g. on the Internet) to prevent the unloading of a
window. Otherwise, a malicious website could fill your screen with windows
that you wouldn't be able to close or otherwise navigate.

Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.
 
If you were working on a Word document on your computer, and had made some
changes to it, and decided that you didn't want the changes after all, would
you want Word to prevent you from shutting it down because some programmer
had decided that you shouldn't? It is, after all, the user's computer,
regardless of the authorship of any web page being hosted in a browser on
that computer. Your ASP.Net page is merely a guest there. Make it a polite
one.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Kevin,

I want to make it a polite one. In fact, what would be more polite than
allowing them to watch (open in another page) the objects on the page (1)
which are represented as links while at the same time being able to change
some textfields on page (1). When they now try to close page (1) to which
they made changes to I DO NOT WANT to hinder them but only remind them that
changes have been made and if they want to save them. If they don't want
they are free to discard the changes. Is this that unfriendly?



Greetings



Daniel



Kevin Spencer said:
If you were working on a Word document on your computer, and had made some
changes to it, and decided that you didn't want the changes after all, would
you want Word to prevent you from shutting it down because some programmer
had decided that you shouldn't? It is, after all, the user's computer,
regardless of the authorship of any web page being hosted in a browser on
that computer. Your ASP.Net page is merely a guest there. Make it a polite
one.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Eric Lawrence said:
No, I haven't seen Microsoft CRM, but IE's security model does not allow
"untrusted" Javascript (e.g. on the Internet) to prevent the unloading
of
a
window. Otherwise, a malicious website could fill your screen with windows
that you wouldn't be able to close or otherwise navigate.

Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.
http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onbeforeunload.asp body
"\n\n-----------------------------------------------------------------------OK.\n-----------------------------------------------------------------------
 
No, not at all, and you can certainly pop up a JavaScript confirm box in the
to ask the user if they really want to quit, attaching it to the body's
"onbeforeunload" event. Here's an example (from the MSDN Library):

<SCRIPT>
function closeIt()
{
event.returnValue = "Any string value here forces a dialog box to \
appear before closing the window.";
}
</SCRIPT>
</HEAD>
<BODY onbeforeunload="closeIt()">

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Daniel Walzenbach said:
Kevin,

I want to make it a polite one. In fact, what would be more polite than
allowing them to watch (open in another page) the objects on the page (1)
which are represented as links while at the same time being able to change
some textfields on page (1). When they now try to close page (1) to which
they made changes to I DO NOT WANT to hinder them but only remind them that
changes have been made and if they want to save them. If they don't want
they are free to discard the changes. Is this that unfriendly?



Greetings



Daniel



Kevin Spencer said:
If you were working on a Word document on your computer, and had made some
changes to it, and decided that you didn't want the changes after all, would
you want Word to prevent you from shutting it down because some programmer
had decided that you shouldn't? It is, after all, the user's computer,
regardless of the authorship of any web page being hosted in a browser on
that computer. Your ASP.Net page is merely a guest there. Make it a polite
one.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

of
exactly
do doing
it The
only
http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onbeforeunload.asp
 
Back
Top