473,396 Members | 2,021 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,396 software developers and data experts.

Stopping Someone from losing their changes Part II

Hi,

I was reading this previous post on how to prompt the user if they want to
save their changes before they exit the form.

I found this piece of code but am not sure where to put it

<script language="javascript">
window.attachEvent( "onbeforeunload", Window_OnBeforeUnload ) ;

function ConfirmBeforeUnload()
{
var result = window.confirm("'Are you sure you want to do this?");
if(!result)
{
return(false);
}
}
</script>

At the end i put this statement
Page.RegisterStartupScript("clientScript", strScript)

If the user clicks that they want to save their changes how do I call a
function in my form from the javascript function.

Regards
Brian
Nov 19 '05 #1
3 1121
Hi bbdobuddy,

You can do this...

<form runat="server" ... onsubmit="javascript:return ConfirmBeforeUnload();">

Guillermo G.

--------------------------------------------------------------------------------
Guillermo González Arroyave :: MCP ASP.Net C# :: DCE4

"bbdobuddy" <bb*******@discussions.microsoft.com> wrote in message news:4A**********************************@microsof t.com...
Hi,

I was reading this previous post on how to prompt the user if they want to
save their changes before they exit the form.

I found this piece of code but am not sure where to put it

<script language="javascript">
window.attachEvent( "onbeforeunload", Window_OnBeforeUnload ) ;

function ConfirmBeforeUnload()
{
var result = window.confirm("'Are you sure you want to do this?");
if(!result)
{
return(false);
}
}
</script>

At the end i put this statement
Page.RegisterStartupScript("clientScript", strScript)

If the user clicks that they want to save their changes how do I call a
function in my form from the javascript function.

Regards
Brian
Nov 19 '05 #2
I did that Guillermo but now where do I put this function
ConfirmBeforeUnload() and if they say thay want to save changes how am I able
to call a VB function

Thanks
Brian

"Guillermo González A." wrote:
Hi bbdobuddy,

You can do this...

<form runat="server" ... onsubmit="javascript:return ConfirmBeforeUnload();">

Guillermo G.

--------------------------------------------------------------------------------
Guillermo González Arroyave :: MCP ASP.Net C# :: DCE4

"bbdobuddy" <bb*******@discussions.microsoft.com> wrote in message news:4A**********************************@microsof t.com...
Hi,

I was reading this previous post on how to prompt the user if they want to
save their changes before they exit the form.

I found this piece of code but am not sure where to put it

<script language="javascript">
window.attachEvent( "onbeforeunload", Window_OnBeforeUnload ) ;

function ConfirmBeforeUnload()
{
var result = window.confirm("'Are you sure you want to do this?");
if(!result)
{
return(false);
}
}
</script>

At the end i put this statement
Page.RegisterStartupScript("clientScript", strScript)

If the user clicks that they want to save their changes how do I call a
function in my form from the javascript function.

Regards
Brian

Nov 19 '05 #3
the onbeforeunload fire for every page unload, even a submit, the event will
fire when the postback completes. to do a save changes, you need to set a
variable on a valid submit, so that the confim doesn't appear on every
navigate. you should also have a dirty variable that says whether any
changes where made. just add a onchange event handler to all controls and
set the variable.

if you want to canel unload, return true. if you want to save, you need to
cancel and start a postback (form.submit()).

-- bruce (sqlwork.com)


"bbdobuddy" <bb*******@discussions.microsoft.com> wrote in message
news:4A**********************************@microsof t.com...
Hi,

I was reading this previous post on how to prompt the user if they want to
save their changes before they exit the form.

I found this piece of code but am not sure where to put it

<script language="javascript">
window.attachEvent( "onbeforeunload", Window_OnBeforeUnload ) ;

function ConfirmBeforeUnload()
{
var result = window.confirm("'Are you sure you want to do this?");
if(!result)
{
return(false);
}
}
</script>

At the end i put this statement
Page.RegisterStartupScript("clientScript", strScript)

If the user clicks that they want to save their changes how do I call a
function in my form from the javascript function.

Regards
Brian

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: pleake | last post by:
Following is a logon.asp script. This script works when IIS is reset each day. The epapi object is a vendor api program I do not have the code for! The logon process involves three servers: ...
32
by: Neil Ginsberg | last post by:
We're using SQL Server 7 with an Access 2000 MDB as a front end with ODBC linked tables. I recently created a new set of tables for the app, and users are complaining that unsaved data is being...
1
by: Perre Van Wilrijk | last post by:
Hi, I've got a full text index which works fine, SQLSERVER2000/WIN 2000 SERVER. The system requires to update indexes immediately, so I use a timestamp field to enable this. No problems so...
6
by: Nad | last post by:
Hello, I need some help with this: I am trying to update some data using XmlTextWriter. I instantiate first and then do some validation and then copy data into the dataset. Finally I commit...
9
by: UJ | last post by:
I have a page where the user can make changes to some DB stuff. It's not saved until they hit the save button. I'd like to have it so that if they attempt to navigate somewhere else, I give them a...
15
by: graham | last post by:
Hi all, <bitching and moaning section> I am asking for any help I can get here... I am at the end of my tether... I don;t consider myself a genius in any way whatsoever, but I do believe I have...
5
by: Phil Latio | last post by:
I have 2 virtually identical tables and wish to move data between them. Basically one table is called "live_table" and the other is named "suspended_table" and the only difference is that the...
4
by: Jeff | last post by:
Hi, I'd like to write Javascript that stops animated gifs from animating. On Firefox, at least, window.stop(); does the trick, although it stops everything on the page and is kind of...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.