4

So i have to show a jquery UI Dialog from codebehind.
I've tried everything: this, this, this, and also changed those answers to test if it works with me but is not working.
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.

Can anyone give me a workaround please? It would be apreciated.
Thank you.

My aspx:

HEAD
<script type="text/javascript">

    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"));
        });
    }

</script>
ENDHEAD
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:UpdatePanel runat="server" ID="upTotal">
    <ContentTemplate>
        <script type="text/javascript">
            Sys.Application.add_load(BindEvents);                
        </script>....
 <tr>
          <td class="Izquierda">
                (*) Número único:
          </td>
          <td class="Derecha">
             <asp:TextBox ID="tbNumeroUnico" runat="server"></asp:TextBox>
             <asp:Button ID="btMostrarIgualesEntrante" runat="server" Text="Revisar si ya existe"
                                                    OnClick="MostrarVentanaIgualesEntrante" ValidationGroup="none" CausesValidation="false"
                                                    CssClass="Button" />                 
             <asp:Label runat="server" ID="lbNumeroUnicoEntrante" Text="Debe digitar el formato correcto del número único (completo)"
                                                    Visible="false" CssClass="ErrorCampo"></asp:Label>
          </td>
       </tr>...
        <div id="DivMostrarIguales" title="Número Único Igual">
            WhatEver              
        </div>           
    </ContentTemplate>
</asp:UpdatePanel>
</asp:Content>  

My .CS functions:

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 && 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')");            
    }
Community
  • 1
  • 1
euther
  • 2,556
  • 5
  • 24
  • 36
  • Have you used a javascript debugger to check for errors? Firebug is my favourite. Also add a ";" to here ".dialog('open')", it should be ".dialog('open');" – Hawxby Mar 28 '11 at 17:00

1 Answers1

6

First make a call to dialog to create it.

.dialog({ autoOpen: false }) //{} = settings

and then open it..

.dialog('open')
Robin Maben
  • 22,194
  • 16
  • 64
  • 99
  • thanks for your quick reply conqenator, it works perfectly. i'm using it this way: runjQueryCode("dlg = $('#DivMostrarIguales').dialog({autoOpen: false,show: 'fold',hide: 'clip',width: 500,height: 500}); $('#DivMostrarIguales').dialog('open')"); – euther Mar 28 '11 at 17:05
  • Well, I'm glad it helped.. :) – Robin Maben Mar 28 '11 at 18:57