473,383 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Window Save Message

92
I am developing one website, if user close the window without saving their work, it should show some error message as "Do u want to save the changes?". How can i do this using ASP.NET(C#) codes.
Apr 29 '09 #1
1 1809
Frinavale
9,735 Expert Mod 8TB
You cannot do this using C#.
You have to do this using JavaScript because C# runs on the server and it cannot detect when the browser is being closed; whereas, JavaScript runs in the browser (client side) and can detect when the page is being closed..... Well, ok that's not the full truth, JavaScript can detect when the page is being unloaded.

There is a JavaScript event that is raised whenever the page is unloaded by the browser. It is called the onbeforeunload event. This method lets you cancel the unload event just in case the user wants to.

The only thing is that this event is raised every time the page is unloaded. This includes when the page is unloaded during full page post backs to the browser. So it does not necessarily mean that the user is closing the window or leaving the page.

Therefore you're going to have to indicate when not to display the "are you sure" message.

When do you not want to display this message?
Well whenever it's one of your controls that cause the unload event to happen of course :)

How do you do this?

Well, that's up to you...but I think it would involve having all of your controls that post back to the server call a method that sets a boolean that indicates it's a valid postback so that the message isn't shown by the method that handles the onbeforeunload event...(hehe run on sentences are fun)

Likewise you need to track if any changes are made.
This means that all of the input controls on the page need to call a method that indicates that the message should be displayed whenever a change to that input control takes place......you'll have to remember this between page post backs too so it's best to store this in a hidden field ;)

That should get you pointed in the right direction.

-Frinny
May 1 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: chon | last post by:
I have an ASP page that is sent a file location as a parameter. It opens this file, loads the ADODB.Stream object and does a binary write to the page forcing the download dialog to appear. This...
4
by: Max Dupenois | last post by:
I've seen numerous articles with similair (similar sp?) titles to this in my search.. unfortunately none of them seem to contain what i want, (or if they do i need someone to point out my stupidity...
4
by: GrantS | last post by:
I am having a problem closing a popup window opened modally. When I try to close the window (when the user hits save button and the data has been processed), the Popup window opens as a full screen...
8
by: J Gao | last post by:
Hi, experts, On a button click, I need to save some data to the session object. Then open a new window. The new window will use the session data saved in the first window. I don't want use to...
4
by: DM | last post by:
Is there any way, using a server control, to execute a routine (say, add record to database) and then close the browser window. I'm having a difficult time doing this using a master\detail model...
4
by: Kenneth | last post by:
Hi, I have two forms, parentForm and childForm. parentForm has a button(btn1) and a grid. childForm has a couple of textboxes and a button. The button on parentForm opens a new window of...
14
by: Paul | last post by:
Hi I have 2 functions in java script, one opens a second window-this works, the other is supposed to close this second window, does not seem to be working. Just wondering if anyone had any ideas....
2
by: iloveprincess | last post by:
Hi, I'm developing windows application using VB.Net 2005. I would like to send 'save' message using 'SendMessage' API to the excel appication. I've already got a handle of the excel window with...
1
by: ace danger | last post by:
I have some javascript that works in Firefox 2 but not in IE 7. In the parent page, a user clicks a link and a new window is opened so that they can maintain some values. When the user is...
11
by: V S Rawat | last post by:
using Javascript, I am opening a web-based url in a popup window. MyWin1=Window.Open(url, "mywindow") There is a form (form1) in the url in that popup window, I need to submit that form. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.