ClientScript无法使用AJAX UpdateProgress

时间:2012-07-16 05:05:59

标签: c# asp.net ajax html5

我有一个订单输入页面可能需要一段时间才能处理,用户认为浏览器已冻结并关闭它。这是一个弹出式浏览器,当单击cmdAdd按钮时,文本框中的项目将写入数据库,子窗口将关闭,父级将刷新以查看更改。目前工作正常。

我添加了一个AJAX UpdateProgress以向用户提供一些反馈,但现在cmdAdd浏览器没有关闭而且父级没有更新。进度指示器显示,数据库已更新,但就是这样。有什么想法吗?

注意:UpdateProgress指标在网站的其他地方使用,没有问题,就在我在弹出子窗口中使用它时。 cmdAdd_click在没有updateProgress控件的情况下正常工作(子节点已关闭,父节点已刷新)

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:

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

2 个答案:

答案 0 :(得分:1)

Ajax在您的Asp.net网站中工作,您需要先在您的aspx页面添加Scriptmanager,因为ScriptManager控件管理启用了AJAX的客户端脚本ASP.NET网页。默认情况下,ScriptManager控件会将Microsoft Ajax Library的脚本注册到页面。这使客户端脚本可以使用类型系统扩展和 支持部分页面呈现和Web服务调用等功能。

如果您仍然遇到问题,请在代码后面的文件中使用ScriptManager.RegisterStartupScript代替ClientScript.RegisterStartupScript 与您的aspx页面上的scriptamanager一起。

答案 1 :(得分:0)

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

ScriptManager.RegisterStartupScript(...