title: Open jQuery UI Dialog from Code Behind
body: <p>I am kind of new with jQuery and JavaScript, and I ran into a problem. </p>
  
  <p>I am having some problems to open the jQuery UI Dialog Box from my ButtonField within the Gridview:</p>
  
  <pre><code>&lt;asp:ButtonField ButtonType="link" Text="Modify Deadline" Visible="true" runat="server" CommandName="modifyDeadline" ControlStyle-CssClass="button" ItemStyle-CssClass="sliderPopupOpener"/&gt;
  </code></pre>
  
  <p>At first I tried to give a class to the above and named it sliderPopupOpener, and make it open the jQuery Popup when clicked as below: </p>
  
  <pre><code>$(".sliderPopupOpener").click(function () {
    $("#sliderPopup").dialog("open");
  });
  </code></pre>
  
  <p>However, this was not working because of the postback, apart from that, it also does not work with my approach. Since I would like to get some data from the database before showing the jQuery UI Dialog. So I think the best approach is to call the Dialog function from the Code Behind.</p>
  
  <p>How can I do this?</p>
  
  <p>I tried this approach, but it did not work, I am not sure if I am doing something wrong. </p>
  
  <pre><code>if (e.CommandName == "modifyDeadline")
  {
       string sliderPopupFunction = @" &lt;script type=""text/javascript""&gt; 
                                          $(function () { 
                                              jQuery(function () {
                                                  $(""#sliderPopup"").dialog(""open""); 
                                              }
                                           });
                                      &lt;/script&gt;";
      ClientScript.RegisterStartupScript(typeof(Page), "key", sliderPopupFunction);
  }
  </code></pre>
  
  <p>Is the above possible? If so, what am I doing wrong?</p>
  
  <p>EDIT:</p>
  
  <p>I noticed everyone is giving their answers with a way around this, rather than telling me whether this is possible just by calling the jQuery function from the Code Behind. Although I appreciate other solutions, I would appreciate if I could get this to work, with the least effort possible, through the code behind, since I have everything ready that way. </p>