Solved

Are you sure you want to leave this page warning

Posted on 2014-03-18
3
1,894 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

617 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