更新面板中带有asp按钮触发器的Jquery UI对话框

时间:2011-10-04 07:59:13

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

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

以下是见解..

用于在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,dint work。
  2. 为div添加了一个更新面板以及runat =“Server”,仍然是dint work ..
  3. 任何人都可以帮我解决可能的解决方案吗?

2 个答案:

答案 0 :(得分:2)

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

我将更新面板和runat参数添加到Div。

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

将代码更改为。

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

答案 1 :(得分:0)

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

克里斯