no suggestions on this one??

  • Thread starter Alejandro Penate-Diaz
  • Start date
A

Alejandro Penate-Diaz

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");

}
 
R

Robbe Morris [C# MVP]

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.
 
A

Alejandro Penate-Diaz

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.
 
M

mszanto

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/issues/04/08/CuttingEdge/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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top