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

Stopping somebody from losing changes when they navigate away from a page.

P: n/a
UJ
I have a page where the user can make changes to some DB stuff. It's not
saved until they hit the save button. I'd like to have it so that if they
attempt to navigate somewhere else, I give them a warning (and preferably
the ability to stop them) if they don't want to lose their changes. In other
words - an 'Are you sure you want to do this?' message box.

Can anybody help me on how to do this?

TIA - J.
Nov 19 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
The only way I can think of acomplishing this is through JavaScript. I don't
know the exact code off the top of my head but if you ask in a JavaScript
news group or just google for it I'm sure you could find it.

It is important to note that if the user has JS disabled that solution would
not work.

"UJ" wrote:
I have a page where the user can make changes to some DB stuff. It's not
saved until they hit the save button. I'd like to have it so that if they
attempt to navigate somewhere else, I give them a warning (and preferably
the ability to stop them) if they don't want to lose their changes. In other
words - an 'Are you sure you want to do this?' message box.

Can anybody help me on how to do this?

TIA - J.

Nov 19 '05 #2

P: n/a
Here's some server side code that uses javascript to display a confirmation
message.

myDeleteButton.Attributes.Add("onclick", _
"return confirm('Are you sure you want to delete?');")

In this example, the Delete button will post back only if the person
confirms they want to delete. Otherwise your server code is never called in
response to the button click.

Here's a more detailed analysis of your options, including a free control
that can handle many of the options for you.
http://SteveOrr.net/articles/ClientSideSuite.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"UJ" <fr**@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have a page where the user can make changes to some DB stuff. It's not
saved until they hit the save button. I'd like to have it so that if they
attempt to navigate somewhere else, I give them a warning (and preferably
the ability to stop them) if they don't want to lose their changes. In
other words - an 'Are you sure you want to do this?' message box.

Can anybody help me on how to do this?

TIA - J.

Nov 19 '05 #3

P: n/a
That doesn't appear to be what he's looking for, I got the impression if
someone tries to nav from his page, regardless of wether they interacted with
the page itself (ie: they hit the back button) a message box pops up.

"Steve C. Orr [MVP, MCSD]" wrote:
Here's some server side code that uses javascript to display a confirmation
message.

myDeleteButton.Attributes.Add("onclick", _
"return confirm('Are you sure you want to delete?');")

In this example, the Delete button will post back only if the person
confirms they want to delete. Otherwise your server code is never called in
response to the button click.

Here's a more detailed analysis of your options, including a free control
that can handle many of the options for you.
http://SteveOrr.net/articles/ClientSideSuite.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"UJ" <fr**@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I have a page where the user can make changes to some DB stuff. It's not
saved until they hit the save button. I'd like to have it so that if they
attempt to navigate somewhere else, I give them a warning (and preferably
the ability to stop them) if they don't want to lose their changes. In
other words - an 'Are you sure you want to do this?' message box.

Can anybody help me on how to do this?

TIA - J.


Nov 19 '05 #4

P: n/a
UJ,
You can dio this with the javascript OnUnLoad event...

Detailed documentaion and sample are available at following page

http://msdn.microsoft.com/library/de...s/onunload.asp
Sreejith
"UJ" wrote:
I have a page where the user can make changes to some DB stuff. It's not
saved until they hit the save button. I'd like to have it so that if they
attempt to navigate somewhere else, I give them a warning (and preferably
the ability to stop them) if they don't want to lose their changes. In other
words - an 'Are you sure you want to do this?' message box.

Can anybody help me on how to do this?

TIA - J.

Nov 19 '05 #5

P: n/a
UJ
Yes. I don't want a delete button per se. I want it that if they have made
changes (which I already know) they get a message asking them to confirm the
losing of the changes.

Let me ask this - what all can you do in the page unload event? Can you stop
the unloading from happening? What I really want is to have a way to say -
the page is unloading, check a few things and stop it from unloading if need
be.

TIA - J.

"Jason L Lind" <Ja********@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...
That doesn't appear to be what he's looking for, I got the impression if
someone tries to nav from his page, regardless of wether they interacted
with
the page itself (ie: they hit the back button) a message box pops up.

"Steve C. Orr [MVP, MCSD]" wrote:
Here's some server side code that uses javascript to display a
confirmation
message.

myDeleteButton.Attributes.Add("onclick", _
"return confirm('Are you sure you want to delete?');")

In this example, the Delete button will post back only if the person
confirms they want to delete. Otherwise your server code is never called
in
response to the button click.

Here's a more detailed analysis of your options, including a free control
that can handle many of the options for you.
http://SteveOrr.net/articles/ClientSideSuite.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"UJ" <fr**@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
>I have a page where the user can make changes to some DB stuff. It's not
>saved until they hit the save button. I'd like to have it so that if
>they
>attempt to navigate somewhere else, I give them a warning (and
>preferably
>the ability to stop them) if they don't want to lose their changes. In
>other words - an 'Are you sure you want to do this?' message box.
>
> Can anybody help me on how to do this?
>
> TIA - J.
>
>


Nov 19 '05 #6

P: n/a
You may also be able to take advantage of the client side OnClose event.
Here's more info:
http://www.mozilla.org/docs/dom/domr...dow_ref56.html

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
"Sreejith Ram" <Sr*********@discussions.microsoft.com> wrote in message
news:0D**********************************@microsof t.com...
UJ,
You can dio this with the javascript OnUnLoad event...

Detailed documentaion and sample are available at following page

http://msdn.microsoft.com/library/de...s/onunload.asp
Sreejith
"UJ" wrote:
I have a page where the user can make changes to some DB stuff. It's not
saved until they hit the save button. I'd like to have it so that if they
attempt to navigate somewhere else, I give them a warning (and preferably
the ability to stop them) if they don't want to lose their changes. In
other
words - an 'Are you sure you want to do this?' message box.

Can anybody help me on how to do this?

TIA - J.

Nov 19 '05 #7

P: n/a
This is IE Specific Code

<script language="javascript">
window.attachEvent( "onbeforeunload", Window_OnBeforeUnload ) ;

function ConfirmBeforeUnload()
{
var result = window.confirm("'Are you sure you want to do this?");
if(!result)
{
return(false);
}
}
</script>

if this doesnt work, you may also want to try the same with
window.onunload = ConfirmBeforeUnload;
Sreejith

"Sreejith Ram" wrote:
UJ,
You can dio this with the javascript OnUnLoad event...

Detailed documentaion and sample are available at following page

http://msdn.microsoft.com/library/de...s/onunload.asp
Sreejith
"UJ" wrote:
I have a page where the user can make changes to some DB stuff. It's not
saved until they hit the save button. I'd like to have it so that if they
attempt to navigate somewhere else, I give them a warning (and preferably
the ability to stop them) if they don't want to lose their changes. In other
words - an 'Are you sure you want to do this?' message box.

Can anybody help me on how to do this?

TIA - J.

Nov 19 '05 #8

P: n/a

This should help you.
http://aspnet.4guysfromrolla.com/articles/101304-1.aspx
"UJ" <fr**@nowhere.com> wrote in message news:#$**************@TK2MSFTNGP09.phx.gbl...
I have a page where the user can make changes to some DB stuff. It's not
saved until they hit the save button. I'd like to have it so that if they
attempt to navigate somewhere else, I give them a warning (and preferably
the ability to stop them) if they don't want to lose their changes. In other
words - an 'Are you sure you want to do this?' message box.

Can anybody help me on how to do this?

TIA - J.

Nov 19 '05 #9

P: n/a
Check this out.
http://aspnet.4guysfromrolla.com/articles/101304-1.aspx
"UJ" <fr**@nowhere.com> wrote in message news:#$**************@TK2MSFTNGP09.phx.gbl...
I have a page where the user can make changes to some DB stuff. It's not
saved until they hit the save button. I'd like to have it so that if they
attempt to navigate somewhere else, I give them a warning (and preferably
the ability to stop them) if they don't want to lose their changes. In other
words - an 'Are you sure you want to do this?' message box.

Can anybody help me on how to do this?

TIA - J.

Nov 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.