【问题标题】:open jQuery Dialog from codebehind从代码隐藏打开 jQuery 对话框
【发布时间】:2011-07-24 15:47:24
【问题描述】:

所以我必须从代​​码隐藏中显示一个 jquery UI 对话框。
我已经尝试了所有方法:thisthisthis,并且还更改了这些答案以测试它是否适用于我但不起作用。
我正在使用第一个解决方案,因为它是有组织的。如果我使用 alert('whatever') 而不是我的 jquery 对话框代码,它会起作用。所以我知道它的工作原理,但对话框没有任何反应。我也用colorbox试过了,也没用。

谁能给我一个解决方法吗?将不胜感激。
谢谢你。

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

【问题讨论】:

  • 您是否使用过 javascript 调试器来检查错误?萤火虫是我的最爱。还要加一个“;”到这里“.dialog('open')”,应该是“.dialog('open');”

标签: jquery asp.net jquery-ui jquery-ui-dialog


【解决方案1】:

首先调用对话框来创建它。

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

然后打开它..

.dialog('open')

【讨论】:

  • 感谢您的快速回复 conqenator,它运行良好。我这样使用它: runjQueryCode("dlg = $('#DivMostrarIguales').dialog({autoOpen: false,show: 'fold',hide: 'clip',width: 500,height: 500}); $('#DivMostrarIguales').dialog('open')");
  • 好吧,我很高兴它有帮助.. :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多