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
Guillermo Gonz=A1lez A. - 21 Jul 2005 20:54 GMT
Hi bbdobuddy,
You can do this...
<form runat="server" ... onsubmit="javascript:return ConfirmBeforeUnload();">
Guillermo G.
--------------------------------------------------------------------------------
Guillermo Gonz=A1lez 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
bbdobuddy - 21 Jul 2005 21:04 GMT
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,
>
[quoted text clipped - 35 lines]
> Regards
> Brian
Bruce Barker - 22 Jul 2005 02:29 GMT
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)
> Hi,
>
[quoted text clipped - 24 lines]
> Regards
> Brian