469,914 Members | 2,329 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,914 developers. It's quick & easy.

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 1040
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

32 posts views Thread by Neil Ginsberg | last post: by
1 post views Thread by Perre Van Wilrijk | last post: by
4 posts views Thread by Jeff | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.