By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,656 Members | 748 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,656 IT Pros & Developers. It's quick & easy.

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

P: n/a
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,'Ful lscreen=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

Nov 18 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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
ja******@online.microsoft.com

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=?=" <da**********************@freudenberg.de>Subject: How to prevent a changed page from beeing closed???
Date: Mon, 9 Feb 2004 07:06:07 -0800
Lines: 32
Message-ID: <58**********************************@microsoft.co m>
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,'Ful lscreen=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


Nov 18 '05 #2

P: n/a
Jim,

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

Thank you a lot!

Daniel
"Jim Cheshire [MSFT]" <ja******@online.microsoft.com> schrieb im Newsbeitrag
news:6j****************@cpmsftngxa07.phx.gbl...
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
ja******@online.microsoft.com

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=?=" <da**********************@freudenberg.de>
Subject: How to prevent a changed page from beeing closed???
Date: Mon, 9 Feb 2004 07:06:07 -0800
Lines: 32
Message-ID: <58**********************************@microsoft.co m>
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:208562NNTP-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,'Ful lscreen=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

Nov 18 '05 #3

P: n/a
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/a...foreunload.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" <da**********************@freudenberg.de> wrote in
message news:58**********************************@microsof t.com...
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,'Ful lscreen=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

Nov 18 '05 #4

P: n/a
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

"Eric Lawrence [MSFT]" <e_********@hotmail.com> schrieb im Newsbeitrag
news:Oz**************@TK2MSFTNGP10.phx.gbl...
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/a...foreunload.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" <da**********************@freudenberg.de> wrote in
message news:58**********************************@microsof t.com...
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,'Ful lscreen=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


Nov 18 '05 #5

P: n/a
Daniel,

You might want to try inetexplorer.scripting.

Jim Cheshire, MCSE, MCSD [MSFT]
ASP.NET
Developer Support
ja******@online.microsoft.com

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

--------------------
From: "Daniel Walzenbach" <da**********************@freudenberg.de>
References: <58**********************************@microsoft.co m> <6j**************@cpmsftngxa07.phx.gbl>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: <Ow*************@tk2msftngp13.phx.gbl>
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!TK2MSFTN GP08.phx.gbl!tk2msftngp13.
phx.gblXref: 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.programmin g ???

Thank you a lot!

Daniel
"Jim Cheshire [MSFT]" <ja******@online.microsoft.com> schrieb im Newsbeitragnews:6j****************@cpmsftngxa07.phx.gbl...
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
ja******@online.microsoft.com

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=?="

<da**********************@freudenberg.de>
>Subject: How to prevent a changed page from beeing closed???
>Date: Mon, 9 Feb 2004 07:06:07 -0800
>Lines: 32
>Message-ID: <58**********************************@microsoft.co m>
>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.gblmicrosoft.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,'Ful lscreen=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
>



Nov 18 '05 #6

P: n/a
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.

"Daniel Walzenbach" <da**********************@freudenberg.de> wrote in
message news:eZ**************@TK2MSFTNGP09.phx.gbl...
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

"Eric Lawrence [MSFT]" <e_********@hotmail.com> schrieb im Newsbeitrag
news:Oz**************@TK2MSFTNGP10.phx.gbl...
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/a...foreunload.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" <da**********************@freudenberg.de> wrote in
message news:58**********************************@microsof t.com...
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,'Ful lscreen=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



Nov 18 '05 #7

P: n/a
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 [MSFT]" <e_********@hotmail.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
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.
"Daniel Walzenbach" <da**********************@freudenberg.de> wrote in
message news:eZ**************@TK2MSFTNGP09.phx.gbl...
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

"Eric Lawrence [MSFT]" <e_********@hotmail.com> schrieb im Newsbeitrag
news:Oz**************@TK2MSFTNGP10.phx.gbl...
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/a...foreunload.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" <da**********************@freudenberg.de> wrote in
message news:58**********************************@microsof t.com...
> 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,'Ful lscreen=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
>



Nov 18 '05 #8

P: n/a
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" <ke***@takempis.com> schrieb im Newsbeitrag
news:u3**************@TK2MSFTNGP12.phx.gbl...
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 [MSFT]" <e_********@hotmail.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
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.

"Daniel Walzenbach" <da**********************@freudenberg.de> wrote in
message news:eZ**************@TK2MSFTNGP09.phx.gbl...
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

"Eric Lawrence [MSFT]" <e_********@hotmail.com> schrieb im Newsbeitrag
news:Oz**************@TK2MSFTNGP10.phx.gbl...
> 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/a...foreunload.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" <da**********************@freudenberg.de> wrote in > message news:58**********************************@microsof t.com...
> > 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,'Ful lscreen=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
> >
>
>



Nov 18 '05 #9

P: n/a
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" <da**********************@freudenberg.de> wrote in
message news:uY**************@TK2MSFTNGP10.phx.gbl...
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" <ke***@takempis.com> schrieb im Newsbeitrag
news:u3**************@TK2MSFTNGP12.phx.gbl...
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 [MSFT]" <e_********@hotmail.com> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
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.

"Daniel Walzenbach" <da**********************@freudenberg.de> wrote in
message news:eZ**************@TK2MSFTNGP09.phx.gbl...
> 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
>
>
>
> "Eric Lawrence [MSFT]" <e_********@hotmail.com> schrieb im
Newsbeitrag > news:Oz**************@TK2MSFTNGP10.phx.gbl...
> > 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/a...foreunload.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" <da**********************@freudenberg.de> wrote in
> > message news:58**********************************@microsof t.com...
> > > 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,'Ful lscreen=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
> > >
> >
> >
>
>



Nov 18 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.