Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2005

Tip: Looking for answers? Try searching our database.

Stopping Someone from losing their changes Part II

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bbdobuddy - 21 Jul 2005 20:26 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.