![]() |
|
|
|
#1 |
|
Hi. I have posted this question three times in this newsgroup as well as
microsoft.public.scripting.jscript and have get no answer yet. Now I dont know if my question is too stupid or too weird, though usually my stupid questions get some funny answers. I am gona try once more before I give up on this one. I need to ask the user whether to save the information on a page to a sql server when exiting or navigating away, so I am using this code when clicking the X button (top right close button). Button8 (is an asp.net server control) does that(save to database) when clicked so I am reusing it in my javascript: //this code is launched in the OnBeforeUnload event in the <body> section function HandleOnClose() { if (event.clientY < 0) if (confirm("OK to save changes. Cancel to exit without saving.") ) __doPostBack('Button8','') } The code above works fine, problem comes with the following code that I am using when the user clicks a link to another page, code __doPostBack('Button8','') is never executed. is there a simple work around for what I want to do?: // this code is launched when clickin in my page's links function goToAnotherPage() { if (confirm("OK to save changes. Cancel to show Another Page without saving.") ) __doPostBack('Button8',''); window.navigate("another_page.aspx"); } Alejandro Penate-Diaz |
|
|
|
|
#2 |
|
Posts: n/a
|
You'll need to do exactly what you are avoiding and that is
modifying the links on that page to call your JavaScript function to see if changes have been made (I'm assuming you have some sort of DirtyFlag that gets set if you change anything on the form) and prompting for the save. We have found that our users expect to stay on the same page after the save (if they click ok). Then, if the click the link to exit again, it should exit without prompting them because they have not changed anything. -- 2005 Microsoft MVP C# Robbe Morris http://www.robbemorris.com http://www.masterado.net/home/listings.aspx "Alejandro Penate-Diaz" <> wrote in message news:%... > Hi. I have posted this question three times in this newsgroup as well as > microsoft.public.scripting.jscript and have get no answer yet. Now I dont > know if my question is too stupid or too weird, though usually my stupid > questions get some funny answers. I am gona try once more before I give up > on this one. > > I need to ask the user whether to save the information on a page to a > sql server when exiting or navigating away, so I am using this code when > clicking the X button (top right close button). Button8 (is an asp.net > server control) does > that(save to database) when clicked so I am reusing > it in my javascript: > > //this code is launched in the OnBeforeUnload event in the <body> section > function HandleOnClose() > > { > > if (event.clientY < 0) > > if (confirm("OK to save changes. Cancel to exit without saving.") ) > __doPostBack('Button8','') > > } > > > > The code above works fine, problem comes with the following code that I am > using when the user clicks a link to another page, code > __doPostBack('Button8','') is never executed. is there a simple work > around > for what I want to do?: > > > // this code is launched when clickin in my page's links > function goToAnotherPage() > > { > > if (confirm("OK to save changes. Cancel to show Another Page without > saving.") ) __doPostBack('Button8',''); > > > > window.navigate("another_page.aspx"); > > } > Robbe Morris [C# MVP] |
|
|
|
#3 |
|
Posts: n/a
|
I know I need to check for changes in my forms first, but that doesn't
changes my question, I still want to postback to the server and after that I want to navigate away, not to stay in the same page. How come I can postback and close te window but I can not postback and navigate away?? Thanks, alejandro. "Robbe Morris [C# MVP]" <> wrote in message news:... > You'll need to do exactly what you are avoiding and that is > modifying the links on that page to call your JavaScript > function to see if changes have been made (I'm assuming you > have some sort of DirtyFlag that gets set if you change anything > on the form) and prompting for the save. > > We have found that our users expect to stay on the same page > after the save (if they click ok). Then, if the click the link to > exit again, it should exit without prompting them because they > have not changed anything. > > -- > 2005 Microsoft MVP C# > Robbe Morris > http://www.robbemorris.com > http://www.masterado.net/home/listings.aspx > > > > "Alejandro Penate-Diaz" <> wrote in message > news:%... >> Hi. I have posted this question three times in this newsgroup as well as >> microsoft.public.scripting.jscript and have get no answer yet. Now I >> dont know if my question is too stupid or too weird, though usually my >> stupid questions get some funny answers. I am gona try once more before I >> give up on this one. >> >> I need to ask the user whether to save the information on a page to a >> sql server when exiting or navigating away, so I am using this code when >> clicking the X button (top right close button). Button8 (is an asp.net >> server control) does >> that(save to database) when clicked so I am reusing >> it in my javascript: >> >> //this code is launched in the OnBeforeUnload event in the <body> section >> function HandleOnClose() >> >> { >> >> if (event.clientY < 0) >> >> if (confirm("OK to save changes. Cancel to exit without saving.") ) >> __doPostBack('Button8','') >> >> } >> >> >> >> The code above works fine, problem comes with the following code that I >> am >> using when the user clicks a link to another page, code >> __doPostBack('Button8','') is never executed. is there a simple work >> around >> for what I want to do?: >> >> >> // this code is launched when clickin in my page's links >> function goToAnotherPage() >> >> { >> >> if (confirm("OK to save changes. Cancel to show Another Page without >> saving.") ) __doPostBack('Button8',''); >> >> >> >> window.navigate("another_page.aspx"); >> >> } >> > > Alejandro Penate-Diaz |
|
|
|
#4 |
|
Posts: n/a
|
A couple of suggestions...
1. Store a hidden flag on the client that can be read from the server that tells the server side code that you're done with the page. When you do the postback and the server side code is complete, the last thing you do is check this flag and if it indicates that you are done it redirects the page using response.redirect to the new page. 2. If you really need the page to postback, redisplay the current page and then redirect to the new page then repeat step 1 but instead of using response.redirect use RegisterStartupScript to insert some javascript at the end of the form that automatically redirects the page to the new page. 3. An advanced solution (and one of my favorites) is to use asynchronous CallBacks which are still not officially supported in the current version of the .Net Framework. Callbacks allow you make requests to the server side code via xml without submitting the entire page. This creates very efficient use of bandwidth and allows you to dynamically update the contents of a page without having to post back to the server (for example). You could use a callback to send the data you wish to be saved to the server then continue on without waiting for the results or redisplaying the page. For more information check out Dino Espito's article from MSDN Magazine at http://msdn.microsoft.com/msdnmag/is...e/default.aspx You can skip most of the 2.0 stuff and scroll down to the section titled "Script Callbacks in ASP.NET 1.x" mszanto@hotmail.com |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need suggestions for motherboard / RAM / etc. | bigal | Hardware | 0 | 07-26-2006 01:01 PM |
| DVD stores in LA-- suggestions?? | G. M. Watson | DVD Video | 21 | 09-23-2005 11:06 AM |
| Re: Monitor suggestions PLEASE! | Tom MacIntyre | A+ Certification | 2 | 03-06-2004 12:04 AM |
| Re: Monitor suggestions PLEASE! | Mr widgetron | A+ Certification | 1 | 02-29-2004 12:39 PM |
| Any suggestions? | havinfun69nospam@yahoo.com | A+ Certification | 7 | 11-03-2003 10:58 PM |