Solved

Are you sure you want to leave this page warning

Posted on 2014-03-18
3
1,807 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 39938936
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
ID: 39938973
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
ID: 39939635
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
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.

734 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