title: open jQuery Dialog from codebehind
body: <p>So i have to show a jquery UI Dialog from codebehind.<br>
  I've tried everything: <a href="http://blog.dreamlabsolutions.com/post/2009/06/03/run-jQuery-code-from-ASPNET-Server-Side.aspx" rel="nofollow noreferrer">this</a>, <a href="https://stackoverflow.com/questions/1613545/trigger-jquery-ui-dialog-from-codebehind">this</a>, <a href="https://stackoverflow.com/questions/3039714/how-register-call-jquery-function-from-asp-net-usercontrol-from-codebehind-file">this</a>, and also changed those answers to test if it works with me but is not working.<br>
  I'm using the first solution because it's organized. It works if i use alert('whatever') instead of my jquery dialog code. so i know its working, but nothing happens with the dialog. I've tried it with colorbox also, and not working either.</p>
  
  <p>Can anyone give me a workaround please? It would be apreciated.<br>
  Thank you.  </p>
  
  <p>My aspx:  </p>
  
  <pre><code>HEAD
  &lt;script type="text/javascript"&gt;
  
      function BindEvents() {
          $.fx.speeds._default = 1000;
          $(document).ready(function () {                
              var dlg = $("#DivMostrarIguales").dialog({
                  autoOpen: false,
                  show: "fold",
                  hide: "clip",
                  width: 500,
                  height: 500
              });
              dlg.parent().appendTo(jQuery("form:first"));
          });
      }
  
  &lt;/script&gt;
  ENDHEAD
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&gt;
  &lt;asp:UpdatePanel runat="server" ID="upTotal"&gt;
      &lt;ContentTemplate&gt;
          &lt;script type="text/javascript"&gt;
              Sys.Application.add_load(BindEvents);                
          &lt;/script&gt;....
   &lt;tr&gt;
            &lt;td class="Izquierda"&gt;
                  (*) Número único:
            &lt;/td&gt;
            &lt;td class="Derecha"&gt;
               &lt;asp:TextBox ID="tbNumeroUnico" runat="server"&gt;&lt;/asp:TextBox&gt;
               &lt;asp:Button ID="btMostrarIgualesEntrante" runat="server" Text="Revisar si ya existe"
                                                      OnClick="MostrarVentanaIgualesEntrante" ValidationGroup="none" CausesValidation="false"
                                                      CssClass="Button" /&gt;                 
               &lt;asp:Label runat="server" ID="lbNumeroUnicoEntrante" Text="Debe digitar el formato correcto del número único (completo)"
                                                      Visible="false" CssClass="ErrorCampo"&gt;&lt;/asp:Label&gt;
            &lt;/td&gt;
         &lt;/tr&gt;...
          &lt;div id="DivMostrarIguales" title="Número Único Igual"&gt;
              WhatEver              
          &lt;/div&gt;           
      &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  &lt;/asp:Content&gt;  
  </code></pre>
  
  <p>My .CS functions:  </p>
  
  <pre><code>private string getjQueryCode(string jsCodetoRun)
      {
          StringBuilder sb = new StringBuilder();
          sb.AppendLine("$(document).ready(function() {");
          sb.AppendLine(jsCodetoRun);
          sb.AppendLine(" });");
  
          return sb.ToString();
      }
  
      private void runjQueryCode(string jsCodetoRun)
      {
  
          ScriptManager requestSM = ScriptManager.GetCurrent(this);
          if (requestSM != null &amp;&amp; requestSM.IsInAsyncPostBack)
          {
              ScriptManager.RegisterClientScriptBlock(this,
                                                      typeof(Page),
                                                      Guid.NewGuid().ToString(),
                                                      getjQueryCode(jsCodetoRun),
                                                      true);
          }
          else
          {
              ClientScript.RegisterClientScriptBlock(typeof(Page),
                                                     Guid.NewGuid().ToString(),
                                                     getjQueryCode(jsCodetoRun),
                                                     true);
          }
      }
  
      protected void MostrarVentanaIgualesEntrante(object sender, EventArgs e)
      {
          CargarGridMostrarIgualesEntrante();
          runjQueryCode("$('#DivMostrarIguales').dialog('open')");            
      }
  </code></pre>