Solved

Are you sure you want to leave this page warning

Posted on 2014-03-18
3
1,691 Views
Last Modified: 2014-03-22
I noticed on few sites, if the process is not finished and in between user wants to leave the page then the browser shows this warning.

Are you sure you want to leave this page?

Have you saved your files?

[Leave this page] [Stay on this page]


I saw this in the IE but crome also does the same job.


I have asp.net page which has log form which user needs to fill.
I also need to stop user by showing this same message when he tries leave the page without saving the changes first.

how can I do this?
0
Comment
Question by:yadavdep
  • 2
3 Comments
 
LVL 29

Expert Comment

by:Olaf Doschke
Comment Utility
That's about Javascript events.

http://www.technicaladvices.com/2012/03/26/detecting-the-page-leave-event-in-javascript/

I don't know how you best make use of this in ASP.NET, but since it's a client side event it has to be done in Javascript anyway. Do you use jQuery? ASP.NET MVC?

Bye, Olaf.
0
 

Author Comment

by:yadavdep
Comment Utility
Hi Olaf,

 I am using Asp.net and yes I do use Jquery in it
0
 
LVL 29

Accepted Solution

by:
Olaf Doschke earned 175 total points
Comment Utility
Then you can make use of the more specific jQuery event handling.

$(window).bind('beforeunload', function(){
		return 'Are you sure you want to leave without saving changes?';
	});

Open in new window


And like in the other example given, you can decide whether to show such a warning message by checking, if the user entered something into a form element, which should not get lost.

Return null, if you want to let the user leave without further notice.

Bye, Olaf.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now