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

发布于 2024-12-08 10:58:01 字数 2116 浏览 5 评论 0原文

我有一个问题,从更新面板内的按钮调用 Jquery 模态对话框。

这里是见解。

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

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

页面中的按钮。

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

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

<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工作。
  2. 添加了一个更新面板以及 div 的 runat="Server",仍然有效。

任何人都可以帮助我提供可能的解决方案吗?

I have a issue with Jquery Modal dialog being called from a button inside an update panel..

here are the insights..

Javascript used for opening a Jquery modal dialog in aspx page..

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

the button in aspx page..

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

The Div which needs to be called from code behind via javascript..

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

Finally the code behind ..

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

Now the Issue in detail..
Without the update panel the modal dialog pops very fine but makes full post back..

I want to have only a partial post back and hence am using a update panel..

The following are the solutions I have tried..

  1. Added update panel to the existing div, dint work.
  2. added an update panel along with runat="Server" for the div, still dint work..

Can any one help me with possible solutions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深居我梦 2024-12-15 10:58:01

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

我将 update panel 和 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>

将后面的代码改为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;
}

Thanks for your quick reply but I found another solution.

I added both update panel and runat parameters to the 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>

Changed the code behind 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;
}
够钟 2024-12-15 10:58:01

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

克里斯

Could you try injecting the javascript into a Literal control inside UpdatePanel, istead registering it with ClientScriptManager ?

Kris

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文