【问题标题】:Jquery UI Dialog with asp button trigger in update panel更新面板中带有 asp 按钮触发器的 Jquery UI 对话框
【发布时间】:2011-10-04 07:59:13
【问题描述】:

我遇到了从更新面板内的按钮调用 Jquery 模态对话框的问题..

以下是见解..

用于在 aspx 页面中打开 Jquery 模式对话框的 Javascript..

<script type='text/javascript'>
    function openModalDiv(divname) {
        $('#' + divname).dialog({ 
            autoOpen: false, 
            bgiframe: true, 
            closeOnEscape: true, 
            modal: true, 
            resizable: false, 
            height: 'auto', 
            buttons: { Ok: function () { closeModalDiv(divname) } },
            open: function (event, ui) { jQuery('.ui-dialog-titlebar-close').hide(); }
        });
        $('#' + divname).dialog('open');
        ('#' + divname).parent().appendTo($('form:FrmSearch'));
        $('#' + divname).css('overflow', 'hidden')
    }

    function closeModalDiv(divname) {
        $('#' + divname).dialog('close');
    }
</script>

aspx 页面中的按钮..

<asp:UpdatePanel ID="upDialogs" runat="server">
    <ContentTemplate>
        <asp:Button ID="btnOpenDialog" runat="server" Text="Open Dialog" onclick="btnOpenDialog_Click" />
    </ContentTemplate>
</asp:UpdatePanel>

需要通过javascript从后面的代码中调用的Div..

<div id="ErrorDiv2" title="Error" style="visibility:hidden">
    <p><span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>Please select an option among the results and try again!</p>
</div>

最后是后面的代码..

protected void btnOpenDialog_Click(object sender, EventArgs e)
{
    if (ProfileID == null)
    {
        Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorDivOpen", "document.getElementById('ErrorDiv2').style.visibility = 'visible';", true);
        Page.ClientScript.RegisterStartupScript(this.GetType(), "ErrorDivShow", "openModalDiv('ErrorDiv2');", true);  
    }
}

现在详细说明问题.. 如果没有更新面板,模态对话框会非常好地弹出,但会完整回发..

我只想回复部分帖子,因此我正在使用更新面板..

以下是我尝试过的解决方案..

  1. 在现有 div 中添加了更新面板,效果不错。
  2. 为 div 添加了一个更新面板以及 runat="Server",仍然可以正常工作..

谁能帮我解决可能的问题?

【问题讨论】:

    标签: c# jquery asp.net postback jquery-ui-dialog


    【解决方案1】:

    感谢您的快速回复,但我找到了另一个解决方案。

    我在 Div 中添加了更新面板和 runat 参数。

    <asp:UpdatePanel ID="upErrorDiv" runat="server"><ContentTemplate>
        <div runat="server" id="ErrorDiv2" title="Error" style="visibility:hidden">
            <p><span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>Please select an option among the results and try again!</p>
        </div>
    </ContentTemplate></asp:UpdatePanel>
    

    改了as后面的代码。

    if (ProfileID == null)
    {
        ScriptManager.RegisterStartupScript(ErrorDiv2,this.GetType(), "ErrorDivOpen", "document.getElementById('ErrorDiv2').style.visibility = 'visible';", true);
        ScriptManager.RegisterStartupScript(ErrorDiv2,this.GetType(), "ErrorDivShow", "openModalDiv('ErrorDiv2');", true);  
        return;
    }
    

    【讨论】:

      【解决方案2】:

      您可以尝试将 javascript 注入到 UpdatePanel 内的 Literal 控件中,而不是使用 ClientScriptManager 注册它吗?

      克里斯

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-10-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-05
        • 2012-03-11
        • 1970-01-01
        相关资源
        最近更新 更多