How can I gain access to an asynchronous response in synchronous code?
<p>I've got a web page where I need a user to click the save button to save the content of the form back to the web server.</p>

<p>Part of the save is a check of items which may require a prompt to the user that allows them to confirm, edit and reorder items in a javascript popup.</p>

<p>If the prompt is required, I need to be able to access the response from the user, i.e. was the confirm or the cancel button clicked, if the cancel button was clicked, the save process must be stopped, if the confirm button was clicked the save process must continue:</p>

<p>Psuedo code for synchronous behaviour:</p>

<pre><code>function SaveData()
{

    if (itemsRequireValidation)
    {
        if (RESPONSE_CANCEL == ConfirmationDialog.Show()) {
            return;
        }
    }

    ProcessConfirmData(ConfirmationDialog.OutputData);

    //...Do the rest of the save process
}
</code></pre>

<p>Given that:</p>

<ul>
<li><p>The confirmation dialog is a Javascript object that builds some HTML output, there is asynchronous behaviour introduced by way of the fact that we cannot really continue the process until the user clicks either the confirm or the cancel buttons contained within the dialog.</p></li>
<li><p>That blocking code to make the Javascript wait until the user clicks one or the other will have negative behaviour that could either crash the browser or prevent the user from even clicking either of the buttons.</p></li>
</ul>

<p>How can I go about refactoring this to take into account the fact that the dialog box is essentially asynchronous, but I need to process the user interaction as if it were synchronous?</p>

<p>I think really I just need to look at this from another point of view that right now I'm not seeing.</p>
