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

U

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

Guest

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

Steve C. Orr [MVP, MCSD]

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
 
G

Guest

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

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

Guest

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
 

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,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top