title: jQuery Dialog ReOpens after Page Refresh or Page Back
body: <p>I have a GridView with a ButtonField that displays the Project ID for each row.</p>
  
  <p>When the user clicks on the Project ID (ButtonField) it opens a jQuery modal Dialog with a more detailed view of the project. When the user closes the Dialog (using the X in the upper right corner) the Dialog closes and everything is great.</p>
  
  <p><strong>The problem is:</strong> if the user refreshes the page, or goes to a new page and then comes back using the back button, the page refreshes/reopens with the Dialog already opened. It should remain closed.</p>
  
  <p>Can you tell from my code what I'm doing wrong?</p>
  
  <hr>
  
  <p><em>javascript:</em></p>
  
  <pre><code>// set the &lt;div&gt; "dialog-projectDetails" as a jQuery modal dialog.
  $(function () {
               $("#dialog-projectDetails").dialog({ autoOpen: false,
                                                    modal: true,
                                                    resizable: false});
  });
  </code></pre>
  
  <hr>
  
  <p><em>asp:GridView - I've left out most of the styling:</em></p>
  
  <pre><code>&lt;asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False"
  DataSourceID="SqlDataSource2" DataKeyNames="ProjID"
  EnableModelValidation="True" onRowCommand="GridView3_RowCommand"&gt;
  &lt;Columns&gt;
      &lt;%-- Link ButtonType on ProjID to activate modal pop-up --%&gt;
      &lt;asp:ButtonField 
          DataTextField="ProjID" 
          HeaderText="&amp;nbsp;&amp;nbsp;Proj. Id" 
          ShowHeader="True" SortExpression="ProjID"
          ButtonType="Link" CommandName="Select"&gt;
      &lt;/asp:ButtonField&gt;
  
      &lt;asp:BoundField 
          DataField="Projects" 
          HeaderText="Projects"
          SortExpression="Projects"&gt;
      &lt;/asp:BoundField&gt;
  
      &lt;asp:BoundField 
          DataField="Status" 
          HeaderText="Status"
          SortExpression="Status"&gt;
      &lt;/asp:BoundField&gt;
  &lt;/Columns&gt;
  &lt;/asp:GridView&gt; &lt;!-- end GridView3 --&gt;
  </code></pre>
  
  <hr>
  
  <p><em>Code Behind:</em></p>
  
  <pre><code>protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
   {
      if (e.CommandName == "Select")
      {
          int rowIndex = Convert.ToInt32(e.CommandArgument);
          // Retrieve the row that contains the button clicked.
          GridViewRow row = GridView3.Rows[rowIndex];
          string projectID = GridView3.DataKeys[row.RowIndex].Value.ToString();
          SqlDataSourceProjectComments.SelectParameters["ProjectID"].DefaultValue = projectID;
  
          string scriptText = "&lt;script type = 'text/javascript'&gt; $(function(){$('#dialog-projectDetails').dialog('open');})&lt;/script&gt;";
          ClientScript.RegisterClientScriptBlock(this.GetType(), "DisplayProjectDetails", scriptText);
      }
   }
  </code></pre>
  
  <p>Thanks for any suggestions.</p>