2011-03-28 28 views
4

所以我必須展示一個來自代碼隱藏的jQuery UI對話框。
我試過一切:this,this,this,並且還更改了這些答案以測試它是否適用於我,但無效。
我使用第一個解決方案,因爲它是有組織的。它適用於如果我使用alert('whatever')而不是我的jQuery對話框代碼。所以我知道它的工作,但對話框沒有任何反應。我也試過用colorbox也不行,也不行。從代碼隱藏中打開jQuery對話框

任何人都可以給我一個解決方法嗎?這將是一個好消息。
謝謝。

我的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> 

我.CS功能:

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

你有使用JavaScript調試器來檢查錯誤? Firebug是我的最愛。還要添加一個「;」 「.dialog('open')」,它應該是「.dialog('open');」 – Hawxby 2011-03-28 17:00:24

回答

6

首先要以對話框的調用來創建它。

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

,然後打開它..

.dialog('open') 
+0

感謝您的快速回復conqenator,它完美的作品。我以這種方式使用它:runjQueryCode(「dlg = $('#DivMostrarIguales')。dialog({autoOpen:false,show:'fold',hide:'clip',width:500,height:500}); $( '#DivMostrarIguales')對話框( '開放')「); – euther 2011-03-28 17:05:41

+0

嗯,我很高興它幫助.. :) – 2011-03-28 18:57:41