title: jQuery replacement for javascript confirm
body: <p>Let's say I want to prompt the user before allowing them to save a record. So let's assume I have the following button defined in the markup:</p>
  <pre><code>&lt;asp:Button ID=&quot;btnSave&quot; runat=&quot;server&quot; OnClick=&quot;btnSave_Click&quot;&gt;&lt;/asp:Button&gt;
  </code></pre>
  <p>To force a prompt with normal javascript, I could wire the OnClick event for my save button to be something like this (I could do this in <code>Page_Load</code>):</p>
  <pre><code>btnSave.Attributes.Add(&quot;onclick&quot;,
      &quot;return confirm('are you sure you want to save?');&quot;);
  </code></pre>
  <p>The confirm call will block until the user actually presses one of the Yes/No buttons, which is the behavior I want. If the user presses 'Yes', then my <code>btnSave_OnClick</code> method would be called.</p>
  <p>For the jquery dialog that is the equivalent, I tried something like this (see below). But the problem is that unlike javascript confirm(), it's going to get all the way through this function (displayYesNoAlert) and then proceed into my btnSave_OnClick method on the C# side. I need a way to make it &quot;block&quot;, until the user presses the Yes or No button, and then return true or false so the btnSave_OnClick will be called or not called depending on the user's answer.</p>
  <p>Currently, I just gave up and went with javascript's confirm, I just wondered if there was a way to do it.</p>
  <pre><code>function displayYesNoAlert(msg, closeFunction) {
      dialogResult = false;
  
      // create the dialog if it hasn't been instantiated
      if (!$(&quot;#dialog-modal&quot;).dialog('isOpen') !== true) {
  
          // add a div to the DOM that will store our message
          $(&quot;&lt;div id=\&quot;dialog-modal\&quot; style='text-align: left;' title='Alert!'&gt;&quot;).appendTo(&quot;body&quot;);
  
          $(&quot;#dialog-modal&quot;).html(msg).dialog({
              resizable: true,
              modal: true,
              position: [300, 200],
              buttons: {
                  'Yes': function () {
                      dialogResult = true;
                      $(this).dialog(&quot;close&quot;);
                  },
                  'No': function () {
                      dialogResult = false;
                      $(this).dialog(&quot;close&quot;);
                  }
              },
              close: function () {
                  if (closeFunction !== undefined) {
                      closeFunction();
                  }
              }
          });
      }
      $(&quot;#dialog-modal&quot;).html(msg).dialog('open');
  
  }
  </code></pre>