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

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
 
J

Jim Cheshire [MSFT]

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
 
D

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
 
E

Eric Lawrence [MSFT]

You cannot prevent the user from closing the page in this way. The only
option you have is to use the onBeforeOnload event to ask the user if they'd
like to stay on the page. You cannot control what the dialog looks like,
nor what the buttons say.

http://msdn.microsoft.com/workshop/author/dhtml/reference/events/onbeforeunload.asp


--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.


Daniel Walzenbach said:
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;
 
D

Daniel Walzenbach

Eric,



did you ever had a look on Microsoft CRM? They found a way to exactly do
what I'd like to do - in fact I'd like to do it since I saw them doing it
:)



Is there any way to cancel onBeforeOnload to prevent it from firing?



Thanks a lot!



Daniel Walzenbach
 
J

Jim Cheshire [MSFT]

Daniel,

You might want to try inetexplorer.scripting.

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.

--------------------
From: "Daniel Walzenbach" <[email protected]>
References: <[email protected]>
Subject: Re: How to prevent a changed page from beeing closed???
Date: Tue, 10 Feb 2004 01:00:13 +0100
Lines: 123
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: p508beaf2.dip.t-dialin.net 80.139.234.242
Path: cpmsftngxa07.phx.gbl!cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.
phx.gbl
Xref: cpmsftngxa07.phx.gbl microsoft.public.dotnet.framework.aspnet:208738
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

Jim,

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

Thank you a lot!

Daniel


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
 
E

Eric Lawrence [MSFT]

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.
 
K

Kevin Spencer

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.
 
D

Daniel Walzenbach

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-----------------------------------------------------------------------
 
K

Kevin Spencer

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top