简体   繁体   English

ClientScript无法与AJAX UpdateProgress一起使用

[英]ClientScript not working with AJAX UpdateProgress

I have an order entry page that can take a little while to process, and users think that the browser has frozen and the close it. 我有一个订单输入页面,该页面可能需要一段时间才能处理,并且用户认为浏览器已冻结并关闭了。 This is a pop up browser, when the cmdAdd button is clicked the items from the text boxes are written to the database, the child window is closed and the parent is refreshed to see the changes. 这是一个弹出式浏览器,当单击cmdAdd按钮时,会将文本框中的项目写入数据库,关闭子窗口,刷新父窗口以查看更改。 This is currently working fine. 目前工作正常。

I added an AJAX UpdateProgress to give the user some feedback, but now the cmdAdd browser does not close and the parent does not update. 我添加了AJAX UpdateProgress,以向用户提供一些反馈,但是现在cmdAdd浏览器无法关闭,并且父级也不会更新。 The progress indicator shows, and the database is updated, but thats it. 显示进度指示器,并且数据库已更新,仅此而已。 Any ideas? 有任何想法吗?

Note: The UpdateProgress indicator is used elsewhere in the site, without problems, it is just when I use it in the pop-up child window. 注意:UpdateProgress指示器可以在网站的其他位置使用,没有问题,仅当我在弹出式子窗口中使用它时。 The cmdAdd_click works properly without the updateProgress control (child is closed, parent is refreshed) 在没有updateProgress控件的情况下,cmdAdd_click可以正常工作(关闭了子代,刷新了父代)

ASPX: ASPX:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="orderHistory.aspx.cs" Inherits="JWeb.orderHistory" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<!DOCTYPE html>
<html>
    <head id="Head1" runat="server">
        <title>JWebUtils - Order History Sheet</title>
        <link href="App_Themes/Theme/Styles.css" rel="stylesheet" type="text/css" />
        <link href="cssUpdateProgress.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <script type="text/javascript">
            var ModalProgress = '<%= ModalProgress.ClientID %>';         
        </script>
        <DIV style="width: 700px; vertical-align: top; border-collapse: collapse;" class="pageBody">
            <form id="Form1" method="post" runat="server">
                <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
                </asp:ToolkitScriptManager>
                <script type="text/javascript" src="jsUpdateProgress.js"></script>
                <asp:Panel ID="panelUpdateProgress" runat="server" CssClass="updateProgress">
                    <asp:UpdateProgress ID="UpdateProg1" DisplayAfter="0" runat="server">
                        <ProgressTemplate>
                            <div style="position: relative; top: 30%; text-align: center; vertical-align: middle;">
                                <img src="images/loading.gif" style="vertical-align: middle" alt="Processing" />
                                Processing ...
                            </div>
                        </ProgressTemplate>
                    </asp:UpdateProgress>
                </asp:Panel>
                <asp:ModalPopupExtender ID="ModalProgress" runat="server" TargetControlID="panelUpdateProgress" BackgroundCssClass="modalBackground" PopupControlID="panelUpdateProgress" />
<%--                <asp:button id="cmdAdd" tabIndex="5" runat="server" Width="95px" cssClass="dg_buttons" Text="Add to Order" onclick="cmdAdd_Click"></asp:button>
--%>                <asp:UpdatePanel ID="pnlUpdate" runat="server">
                    <ContentTemplate>
                        <TABLE id="Table1" style="WIDTH: 100%;">
                            <TR>
                                <TD class="pageHeader" colspan="2">
                                    <asp:label id="lblTitle" runat="server" Font-Names="Arial" Font-Bold="True">Order History Sheet</asp:label>
                                </TD>
                            </TR>
                            <TR>
                                <TD vertical-align: top;" style="width: 220px;">
                                    <asp:button id="cmdAdd" tabIndex="5" runat="server" Width="95px" 
                                        cssClass="dg_buttons" Text="Add to Order" onclick="cmdAdd_Click"></asp:button>&nbsp;
                                    <asp:button id="cmdClose" tabIndex="5" runat="server" Width="50px" Text="Close" 
                                        CssClass="dg_buttons" onclientclick="window.close(); return false;"></asp:button>&nbsp;
                                    <asp:button id="cmdPrint" tabIndex="5" runat="server" Width="50px" Text="Print" 
                                        CssClass="dg_buttons" CausesValidation="False" UseSubmitBehavior="False"></asp:button>
                                </TD>
                                <TD vertical-align: top;" style="text-align: right; width: 480px;">
                                    <asp:Label ID="lblCustomerName" runat="server"></asp:Label>
                                </TD>
                            </TR>
                            <TR>
                                <TD vertical-align: top;" style="vertical-align: top" colspan="2">
                                    &nbsp;<span class="style1">* Qty Bought is total items purchased in the last 12 
                                    months from the current date </span>
                                    <table style="WIDTH: 100%; vertical-align: top;">
                                        <TR>
                                            <TD colspan="2">
                                                <asp:label id="lblMessage" runat="server" Font-Names="Arial" Font-Size="Small" Width="525px" ForeColor="Red"></asp:label>
                                            </TD>
                                        </TR>
                                        <TR>
                                            <TD colspan="2">
                                                <div class="mGrid">
                                                    << GRIDVIEW OMITTED FOR BEREVITY >>
                                                </div>
                                            </TD>
                                        </TR>
                                    </table>
                                </TD>
                            </TR>
                        </TABLE>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </form>
        </DIV>
        <script type="text/javascript" src="jsUpdateProgress.js"></script>
    </body>
</html>

cmdAdd_Click: cmdAdd_Click:

    protected void cmdAdd_Click(object sender, EventArgs e)
    {
        string qty = null;
        string itemCode = null;
        int orderID = Convert.ToInt32((Session["OrderID"]));
        int seqNum = 0;
        int orderSeqNum = 0;
        string description = null;
        JWebUtils.priceType pricing = default(JWebUtils.priceType);
        double price = 0;
        string type = null;
        ArrayList sqlParams = new ArrayList();
        JWebDB db = new JWebDB();
        System.Text.StringBuilder script = new System.Text.StringBuilder();
        int discount = 0;
        string strDisc = null;
        JWebUtils jweb = new JWebUtils();

        << CODE TO UPDATE DB OMITTED FOR BEREVITY >>

        script.Append("<script language=\"javascript\">");
        script.Append("window.opener.document.forms[0].submit();self.close();");
        script.Append("</script>");

        Session["IsPopup"] = true;

        ClientScript.RegisterStartupScript(this.GetType(), "XYZ", script.ToString());
    }

For Ajax to work in your Asp.net web-site you need to add Scriptmanager at your aspx page first as The ScriptManager control manages client script for AJAX-enabled ASP.NET Web pages. 为了使AjaxAsp.net网站上工作,您需要Scriptmanager在aspx页面上添加Scriptmanager ,因为ScriptManager控件管理启用AJAX的ASP.NET网页的客户端脚本。 By default, the ScriptManager control registers the script for the Microsoft Ajax Library with the page.This enables client script to use the type system extensions and to support features such as partial-page rendering and Web-service calls. 默认情况下, ScriptManager控件在页面上注册Microsoft Ajax的脚本。这使客户端脚本可以使用类型系统扩展名并支持部分页面渲染和Web服务调用等功能。

If still you have problem then in your code behind file use ScriptManager.RegisterStartupScript in place of ClientScript.RegisterStartupScript along with scriptamanager on your aspx page. 如果仍然有问题,则在文件后面的代码中,使用ScriptManager.RegisterStartupScript代替ClientScript.RegisterStartupScript ,并在aspx页面上使用scriptamanager

首先,您应该将ScriptManager添加到页面中,然后使用:

ScriptManager.RegisterStartupScript(...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM