473,698 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Window Save Message

92 New Member
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 1816
Frinavale
9,735 Recognized Expert Moderator Expert
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
8532
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 all works fine. If the user selects "Open" or "Cancel", the window closes, which is the desired behavior. If they select "Save", the location dialog shows up, they save the file and the window remains open. I've tried a number of things to get...
4
8433
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 for me :p ) Anyway I have a file dialog box being opened using Response.AddHeader "Content-Disposition", "attachment;filename=""" & displayName & """" Response.ContentType = "application/binary"
4
34867
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 as a new window. The original window plus the Modally opened Pop remain in a separate window. What I want to do is close the popup and return to the original window with its view state maintained. The control use to fire the popup window...
8
2521
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 click two buttons, one to save the session data and the other one to trigger the java script to open the new window. Your advice is highly appreciated. Jie
4
5080
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 where dialog apsx page is opened when datagrid item on master page is clicked. Would like to be able to have detail open in the html dialog where user can edit record, then click save button to save changes to database, call opener routine to...
4
2305
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 childForm: btn1.Attributes("onclick")="javascript window.open(...."
14
2773
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. Here is the code, the functions are <script language="javascript"> function openwin(){ win_usr=window.open ("control_numinfo.aspx") } function closewin(){
2
2802
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 'FindWindow' API. How can I send 'save' command to external excel window? Actual thing I want to do is I can handle excel application in the winform. My client hope that all staff can use excel application in new window
1
11411
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 finished, they can click either a save or a cancel button. If the user clicks the save button, I want the parent page to be refreshed and then the child window to close. I have this working perfectly in FF2 but it does not in IE. In IE, the parent...
11
5308
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. How do I submit that form1 from the javascript from my current window? Thanks.
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.