Stopping Someone from losing their changes Part II

G

Guest

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
 
G

Guest

Hi bbdobuddy,

You can do this...

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

Guillermo G.

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

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
 
G

Guest

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
 
B

Bruce Barker

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top