简体   繁体   English

使用UpdateProgress的问题

[英]Problems using UpdateProgress

I have a button on my ASP.NET page, which fetches some data from my database and displays it on a gridview. 我的ASP.NET页面上有一个按钮,它从我的数据库中获取一些数据并将其显示在gridview上。

This process takes a while, so I thought I'll add an updateprogress AJAX control. 这个过程需要一段时间,所以我想我会添加一个updateprogress AJAX控件。 Now when I click the button, the updateprogress image shows up and data is being fetched from my database successfully (I checked this from some logs that I have in my DB). 现在,当我单击按钮时,updateprogress图像显示并且数据正在从我的数据库中成功获取(我从我的数据库中的某些日志中检查了这一点)。 But there are 2 issues: 但有两个问题:

(1) The updateprogress image shows only for about 2 minutes. (1)updateprogress图像仅显示约2分钟。 But my buttonclick event takes about 5 minutes to complete. 但我的buttonclick事件大约需要5分钟才能完成。 Basically the updateprogress stops showing up even before my task is complete, which defeats its purpose. 基本上,即使在我的任务完成之前,updateprogress也会停止显示,这会使其失败。

(2) GridView doesn't show up. (2)GridView没有显示出来。 It shows up correctly if I don't use scriptmanager/AJAX. 如果我不使用scriptmanager / AJAX,它会正确显示。

Any ideas? 有任何想法吗?

Some relevant code snippets: 一些相关的代码片段:

<div style="position: absolute; top: 300px; left: 19px; width: 568px; height: 48px;">
    <table>
        <tr>
        <td>
    <asp:Button ID="btnGenerateReport" runat="server" Height="37px" Text="Generate Report" 
        Width="132px" onclick="btnGenerateReport_Click" />
        </td>
        <td class="style5">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <asp:UpdatePanel runat="server" id="Panel">
    <ContentTemplate>
            <asp:UpdateProgress ID="PageUpdateProgress" runat="server">
                <ProgressTemplate>
                    <img runat="server" src="updateprogress.gif" 
                        style="position: static; width: 32px;"> </img></ProgressTemplate>
            </asp:UpdateProgress>
            <div style="position: absolute; top: 423px; left: 9px; width: 795px; height: 984px;">
        <asp:GridView ID="Report" runat="server" 
            AllowSorting="True" AutoGenerateColumns="False" 
            Height="622px" BorderStyle="Solid" 
            Width="779px" PageSize="100" HorizontalAlign="Center">
            <Columns>
                <asp:BoundField HeaderText="AccountId" DataField="AccountId">
                <ControlStyle BorderStyle="Solid" Width="20px" />
                </asp:BoundField>
                <asp:BoundField HeaderText="User Name" ReadOnly="True" DataField="UserName">
                <ControlStyle Width="50px" />
                </asp:BoundField>
                <asp:BoundField HeaderText="C2" ReadOnly="True" 
                    DataField="C2">
                <ControlStyle BorderStyle="Solid" Width="20px" />
                </asp:BoundField>
                <asp:BoundField HeaderText="C1" ReadOnly="True" 
                    DataField="C1">
                <ControlStyle BorderStyle="Solid" Width="20px" />
                </asp:BoundField>
            </Columns>
        </asp:GridView>
    </div>
    </ContentTemplate>
    <Triggers>
            <asp:AsyncPostBackTrigger ControlID="btnGenerateReport" EventName="click" />
    </Triggers>
    </asp:UpdatePanel>
        </td>
        <td>
        <asp:Button ID="btnExportToExcel" runat="server" Text="Export To Excel" 
                Height="37px" Width="132px" onclick="btnExportToExcel_Click" />
        </td>
        </tr>
    </table>
    </div>

Codefile part: 代码文件部分:

protected void btnGenerateReport_Click(object sender, EventArgs e)
        {

            FetchAccounts();
            long startId = FetchAuditData();
            AggregateAuditData(startId);
            dsAnalysisReport = GenerateDataSet();
            if (dsAnalysisReport == null || dsAnalysisReport.Tables.Count == 0)
                lblErrorText.Text = "No Data Found for the input information";
            else
                BindData(dsAnalysisReport);
        }

        public void FetchAccounts()
        {
            using (var sqlConnection = new SqlConnection(ConnectionString))
            {
                sqlConnection.Open();
                cmdstring = @"[spo_FetchAccounts]";
                cmd = new SqlCommand(cmdstring, sqlConnection) { CommandType = CommandType.StoredProcedure };
                cmd.CommandTimeout = 100000;
                cmd.Parameters.Add("@MaxActivationDate", SqlDbType.DateTime);
                cmd.Parameters["@MaxActivationDate"].Value =
                    DateTime.Parse(txtStartDate.Text) - new TimeSpan(1, 0, 0, 0);
                cmd.ExecuteNonQuery();
                sqlConnection.Close();
            }
        }

        public long FetchAuditData()
        {
            using (var sqlConnection = new SqlConnection(ConnectionString))
            {
                sqlConnection.Open(); 
                cmdstring = @"[spo_GetComparisonData]";
                cmd = new SqlCommand(cmdstring, sqlConnection) { CommandType = CommandType.StoredProcedure };
                cmd.CommandTimeout = 100000;
                cmd.Parameters.Add("@StartDate", SqlDbType.DateTime);
                cmd.Parameters["@StartDate"].Value = txtStartDate.Text;
                cmd.Parameters.Add("@EndDate", SqlDbType.DateTime);
                cmd.Parameters["@EndDate"].Value = txtEndDate.Text;
                SqlParameter returnValue = new SqlParameter("@Return_Value", SqlDbType.BigInt);
                returnValue.Direction = ParameterDirection.ReturnValue;
                cmd.Parameters.Add(returnValue);
                cmd.ExecuteNonQuery();
                long startId = long.Parse(cmd.Parameters["@Return_Value"].Value.ToString());
                sqlConnection.Close();
                return startId;
            }
        }

        private void AggregateAuditData(long startId)
        {
            using (var sqlConnection = new SqlConnection(ConnectionString))
            {
                sqlConnection.Open();
                cmdstring = @"[spo_ComparisonTable]";
                cmd = new SqlCommand(cmdstring, sqlConnection) { CommandType = CommandType.StoredProcedure };
                cmd.CommandTimeout = 100000;
                cmd.Parameters.Add("@StartId", SqlDbType.Int);
                cmd.Parameters["@StartId"].Value = startId;
                cmd.ExecuteNonQuery();
                sqlConnection.Close();
            }
        }


        public DataSet GenerateDataSet()
        {

            using (var sqlConnection = new SqlConnection(ConnectionString))
            {
                sqlConnection.Open();
                cmdstring = @"SELECT * FROM XAccounts";
                cmd = new SqlCommand(cmdstring, sqlConnection);
                DataSet ds = new DataSet();
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                da.Fill(ds);
                sqlConnection.Close();
                if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    return ds;
                return null;
            }    
        }

        private void BindData(DataSet ds)
        {
            BindReportGrid(Report, ds.Tables[0]);
        }

        private void BindReportGrid(GridView gridToBind, DataTable dataTableToBind)
        {
            gridToBind.DataSource = dataTableToBind;
            gridToBind.DataBind();
        }

As per issue (1) most likely it is ajax timing out. 根据问题(1),最有可能是ajax超时。 Default timeout is 90 seconds. 默认超时为90秒。 To increase that use ScriptManager's AsyncPostBackTimeout property: 要增加使用ScriptManager的AsyncPostBackTimeout属性:

<asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="400">
</asp:ScriptManager>

If ajax call is timing out, controls on the page might not work correctly so increasing timeout might solve problem (2) as well. 如果ajax调用超时,页面上的控件可能无法正常工作,因此增加超时可能也会解决问题(2)。

Maybe you want this: http://www.codeproject.com/kb/Ajax/ModalUpdateProgress.aspx 也许你想要这个: http//www.codeproject.com/kb/Ajax/ModalUpdateProgress.aspx

替代文字

It works well for me, even with lengthy operations. 它适用于我,即使操作很长。

I have had very same problems with ASP.NET UpdateProgress. 我在ASP.NET UpdateProgress上遇到了同样的问题。 I fixed it by handling script manager events directly: 我通过直接处理脚本管理器事件来修复它:

<script language="javascript" type="text/javascript">

//adding event handlers for ajax initialize request and end request
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(ShowHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(HideHandler);

function ShowHandler(sender, args) {
    //show div with animation
    pcProcessing_ClientInstance.Show();
}
function HideHandler(sender, args) {
    //hide div with animation
    pcProcessing_ClientInstance.Hide();
}

</script>

Seems like your grid is outside the Update panel, if you are using a update panel and you button is inside the update panel and grid is outside the update panel in that case everything will happen at server side but you will not find any changes in the UI. 看起来您的网格位于“更新”面板之外,如果您使用的是更新面板,并且您的按钮位于更新面板内,并且网格位于更新面板之外,那么一切都将在服务器端发生,但您不会发现任何更改。 UI。

Try to place your grid inside the update panel. 尝试将网格放在更新面板中。

将UpdateProgress移到UpdatePanel之外。

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

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