By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

Stopping Someone from losing their changes Part II

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.