Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过JavaScript部分回发期间的BlockUI_Javascript_Jquery_Asp.net_Asp.net Ajax_Blockui - Fatal编程技术网

通过JavaScript部分回发期间的BlockUI

通过JavaScript部分回发期间的BlockUI,javascript,jquery,asp.net,asp.net-ajax,blockui,Javascript,Jquery,Asp.net,Asp.net Ajax,Blockui,我有一个ASP.NET页面WebForm1,它通过OpenForm2 js函数打开一个模式对话框WebForm2,以便进行进一步处理。关闭对话框后,我只需通过JavaScript更新UpdatePanel。现在的问题是,在这个js调用过程中,它不会阻塞UI 只有当我从服务器端的按钮单击调用OpenForm2 js方法时,才会发生这种情况。由于UI已经进入块模式,因此在关闭WebForm2时,它不会等待部分回发JavaScript的完成并取消对UI的阻止 如果我在示例中的按钮2的OnClientC

我有一个ASP.NET页面WebForm1,它通过OpenForm2 js函数打开一个模式对话框WebForm2,以便进行进一步处理。关闭对话框后,我只需通过JavaScript更新UpdatePanel。现在的问题是,在这个js调用过程中,它不会阻塞UI

只有当我从服务器端的按钮单击调用OpenForm2 js方法时,才会发生这种情况。由于UI已经进入块模式,因此在关闭WebForm2时,它不会等待部分回发JavaScript的完成并取消对UI的阻止

如果我在示例中的按钮2的OnClientClick标记中直接调用OpenForm2 js函数,它工作得很好,会一直阻塞UI,直到回发完成

我尝试将部分回发js代码包装到add_endRequest中,但在这种情况下,它会一直调用refreshUpdatePanel js方法,因此阻止/取消阻止UI继续进行。这种情况可能是由于在这种情况下在一个页面上使用了两个add_endRequest造成的吗

我们高度赞赏在这方面提供的任何援助

注意:我使用jQuery blockUI在部分回发期间阻塞页面

WebForm1页面的代码示例如下所示。WebForm2 aspx页面只有一个关闭对话框的按钮和一个相关的js函数

WebForm1.aspx

使用


谢谢

不,这不是问题所在。我刚才也检查了你提出的修改。但是,我也在页面源代码中检查了UpdatePanel的ID是否保持不变。我没有找到解决此问题的方法。但是为了解决这个问题,我在客户端updatepanel回发之前设置了一个超时/延迟。这迫使用户界面再次进入阻塞状态,屏幕上有点闪烁。我已经在示例中更新了上面refreshUpdatePanel js方法中的代码行。
<head runat="server">
    <title></title>
    <script src="js/jquery-1.6.1.min.js" type="text/javascript"></script>
    <script src="js/jquery.blockUI.js" type="text/javascript"></script>
    <script type="text/javascript">
        function OpenForm2() {
            var url = "WebForm2.aspx";
            var width = 950;
            var height = 455; // screen.availHeight - (120 + 65);

            // open modal dialog
            obj = window.showModalDialog(url, window, "dialogWidth:" + width + "px; dialogHeight:" + height + "px; center:yes");

            // partial postback to reflect the changes made by form2
            refreshUpdatePanel();
            //Sys.WebForms.PageRequestManager.getInstance().add_endRequest(refreshUpdatePanel);
            // ** here it doesn't wait for the completion and unblocks the UI **
        }

        function refreshUpdatePanel() {
            //window.__doPostBack('UpdatePanel1', '1');
            // a timeout/delay before a client side updatepanel postback. That compelled the UI to go in blocking again with a little screen flickering.
            setTimeout('__doPostBack("<%= UpdatePanel1.ClientID %>", "1")', 0);
        }

        $(document).ready(function () {
            var prm = Sys.WebForms.PageRequestManager.getInstance();
            prm.add_initializeRequest(InitializeRequest);
            prm.add_endRequest(EndRequest);

            $.blockUI.defaults.css = {};
            function InitializeRequest(sender, args) {
                // Whatever you want to happen when the async callback starts
                $.blockUI();
            }
            function EndRequest(sender, args) {
                // Whatever you want to happen when async callback ends
                $.unblockUI();
            }
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" OnLoad="UpdatePanel1_Load">
        <ContentTemplate>
            <asp:Label ID="Label2" runat="server" Text=""></asp:Label><br />
            <asp:Button ID="Button1" runat="server" Text="Button 1" OnClick="Button1_Click" />
            <asp:Button ID="Button2" runat="server" Text="Button 2" OnClientClick="OpenForm2();return false;" />
        </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
protected void Button1_Click(object sender, EventArgs e)
{
    // some server side processing here
    System.Threading.Thread.Sleep(1000);

    // then calling javascript function to open form2 as modal
    ScriptManager.RegisterClientScriptBlock(UpdatePanel1, UpdatePanel1.GetType(), "Button1Click", "OpenForm2();", true);
}

protected void UpdatePanel1_Load(object sender, EventArgs e)
{
    string parameter = Request["__EVENTARGUMENT"];
    if (parameter == "1")
    {
        System.Threading.Thread.Sleep(3000);
        Label2.Text = DateTime.Now.ToString();
    }
}
 function refreshUpdatePanel() {
        __doPostBack"<%= UpdatePanel1.ClientID %>", '1');
    }
 function refreshUpdatePanel() {
        window.__doPostBack('UpdatePanel1', '1');
    }