asp:UpdateProgress 在点击转发器内的可下载内容后永远不会消失

发布于 2024-12-29 12:07:43 字数 9490 浏览 3 评论 0原文

我有一个 ASP.NET 3.5 页面,其中有一个中继器,其中包含信息行和用于更改其状态的自定义按钮。

假设是这样

btn1 btn2 btn3 Id Title Description Status1 Status2

btn1 和 btn2 分别用来改变 status1 和 2。

btn3 重定向到自定义处理程序,该处理程序发回可下载的 MS-Word 报告。这发生在没有实际离开页面的情况下。

转发器位于 updatePanel 内部,因此我可以更新状态,而不必每次都重新加载整个页面。

当我单击 btn1 或 2 时,加载微调器会像往常一样出现,并在进程完成且状态更改时淡出。

当我单击 btn3 时,加载旋转器会停留在那里,永远不会消失,即使在我完成下载后也是如此。

可能发生什么情况?

处理程序代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using PublishVersionControlCore;
using System.Configuration;

namespace PublishVersionControlWebControl.Handler
{
    public class WordFileHandler : IHttpAsyncHandler
    {
        private HttpContext _context;
        private AsyncTaskDelegate del;
        protected delegate void AsyncTaskDelegate(HttpContext context);

        #region IHttpAsyncHandler Members

        public WordFileHandler()
        {
            this.del = new AsyncTaskDelegate(ProcessRequest);
        }

        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            // Store context
            _context = context;
            return del.BeginInvoke(context, cb, extraData);
        }

        public void EndProcessRequest(IAsyncResult result)
        {
            this.del.EndInvoke(result);
        }

        #endregion

        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            HttpResponse resp = context.Response;
            resp.Clear();
            int workItemId = 0;
            if (Int32.TryParse(context.Request.QueryString["wi"], out workItemId))
            {
                MemoryStream ms = null;
                using (WorkItemReportService.ReportClient client = new WorkItemReportService.ReportClient())
                {
                    byte[] resultFile = client.GenerateWorkReport(
                        new Uri(ConfigurationManager.AppSettings["serverUri"]),
                        workItemId,
                        ConfigurationManager.AppSettings["wordTemplate"]);
                    ms = new MemoryStream(resultFile);
                }

                resp.ContentType = "application/octet-stream";
                resp.AddHeader("content-disposition", String.Format("attachment;filename=RelatorioSimples_WI-{0}.docx", workItemId));
                resp.Buffer = true;                
                ms.WriteTo(resp.OutputStream);
                resp.End();
            }
        }

        #endregion
    }
}

中继器中的 ItemCommand:

if (e.CommandName.Equals("WordExport"))
{
    string uri = HttpContext.Current.Request.RawUrl;
    string url = string.Format("{0}/WordReport.dohx?wi={1}",
    uri.Substring(0, uri.LastIndexOf("/")), wivdata.SystemID);
    Response.Redirect(url);
}

Aspx 页面(我将其全部粘贴,因为我不知道什么是相关的,什么是不相关的):

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="~/ListaDeAtividadesPage.aspx.cs"
    MasterPageFile="~/_layouts/customapplication.master" Inherits="PublishVersionControlWebControl.ListaDeAtividadesPage, PublishVersionControlWebControl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=78508f22b73cda2b" %>

<%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <link rel='stylesheet' text='text/css' href='/_layouts/Extensions/Versioning/css/style.css' />
    <script src="/_layouts/Extensions/Versioning/js/jquery.tools.min.js" type="text/javascript"></script>
    <script src="/_layouts/Extensions/Versioning/js/jquery.corner.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderPageImage" runat="server">
    <img width="145" height="54" alt="Dashboard" src="/_layouts/Microsoft.TeamFoundation/images/notes.png" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
    runat="server">
    <asp:Literal ID="TitleContent" runat="server"></asp:Literal>
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <script type="text/javascript">
        _spOriginalFormAction = document.forms[0].action;
        _spSuppressFormOnSubmitWrapper = true;  
    </script>
    <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="updPanel">
        <ProgressTemplate >
            <div class="follower">
            <asp:Image ID="imgUpdate" CssClass="follower" ImageUrl="/_layouts/Extensions/Versioning/img/ui/ajax-loader.gif"
                runat="server" />
                <span class="follower">Carregando...</span>
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
    <div>
        <asp:UpdatePanel ID="updPanel" runat="server">
            <ContentTemplate>
                <asp:Literal ID="tooltipScript" runat="server" />
                <div class="buttonBar">
                    <hr style="color: #426DA8;" />
                    <asp:Button CssClass="specific" ID="btnUpdateWI" Text="Atualiza WIs da Lista" runat="server"
                        UseSubmitBehavior="false" />
                    <asp:Button CssClass="specific" ID="btnRelatorioScripts" Text="Relatório de Scripts / ZIPs"
                        runat="server" />
                    <asp:Button CssClass="specific" ID="Button1" Text="Relatório de Publicações" runat="server" />
                    <asp:Button CssClass="generic" ID="btnVolta" Text="Volta ao Menu de Versões" runat="server" />
                    <hr style="color: #426DA8;" />
                </div>
                <asp:Repeater ID="rptListaAtividades" runat="server">
                    <HeaderTemplate>
                        <asp:Label ID="comentarioHeader" runat="server"/>
                        <h3>
                            <b class="rollback">Rollback</b> | <b class="emteste">Em Teste</b> | <b class="aindanaoincluido">
                                Ainda não Incluído</b> | <b class="parcialmenteok">Atividade Parcialmente OK</b>
                            | <b class="todosok">Atividade OK em Todas as Lojas</b> | <b class="parcpublicado">Parcialmente Publicada</b> | <b class="publicado">Atividade
                                Publicada</b>
                        </h3>   
                    </HeaderTemplate>
                    <ItemTemplate>
                        <div class="item" style="display: inline-block; font-size: 12px">
                            <asp:ImageButton ToolTip="Gerar Relatório Word" ImageUrl="/_layouts/Extensions/Versioning/img/wordexport.png"
                                CommandName="WordExport" ID="btnWordExport" CssClass="itembutton" runat="server" />
                            <asp:ImageButton ToolTip="Marcar como Rollback" ImageUrl="/_layouts/Extensions/Versioning/img/rollback.png"
                                CommandName="MarkAsRollback" ID="btnItemRollback" CssClass="itembutton" runat="server" />
                            <asp:ImageButton ToolTip="Esta atividade possui código. Clique para sinalizar como apenas procedure/config"
                                ImageUrl="/_layouts/Extensions/Versioning/img/code.png" CommandName="MarkAsProc"
                                ID="btnItemProc" CssClass="itembutton" runat="server" />
                            <asp:Image ToolTip="Esta atividade não possui scripts de banco/zips." ImageUrl="/_layouts/Extensions/Versioning/img/noscript.png"
                                runat="server" CssClass="itembutton" ID="btnItemScript" />
                            <asp:Label ID="labelWI" Text="" runat="server"></asp:Label>
                            <asp:Literal ID="tooltip" runat="server" />
                            <asp:Label ID="labelState" Text="" runat="server"></asp:Label>
                            <span style="color: #4A82CB">
                                <%# DataBinder.Eval(Container.DataItem, "SystemAssignedTo") %>
                                - </span><span style="color: Navy">
                                    <%# DataBinder.Eval(Container.DataItem, "SystemTitle") %>
                                </span>
                            <asp:HiddenField ID="workItemID" runat="server" />
                        </div>
                        <hr class="item" noshade style="color: #4CBDCB; height: 2px; background-color: #4CBDCB" />
                    </ItemTemplate>
                </asp:Repeater>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</asp:Content>

其他详细信息:

  • 这是 WSS 3.0 中的布局页面
  • 我不确定更新面板是它应该在的地方

I have a ASP.NET 3.5 page which has a repeater containing lines of information and custom buttons to change their status.

Suppose it's like this

btn1 btn2 btn3 Id Title Description Status1 Status2

btn1 and btn2 are used to change the status1 and 2 respectively.

btn3 redirects to a custom handler which sends back a downloadable MS-Word report. This happens without actually leaving the page.

The repeater is inside an updatePanel so I can update the statuses without having to reload the entire page everytime.

When I click btn1 or 2, the loading spinner appears as usual, and fades out when the process is completed and the status is changed.

When I click btn3, the loading spinner stays there, never going out, even after I finish my download.

What could be happening ?

Handler code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using PublishVersionControlCore;
using System.Configuration;

namespace PublishVersionControlWebControl.Handler
{
    public class WordFileHandler : IHttpAsyncHandler
    {
        private HttpContext _context;
        private AsyncTaskDelegate del;
        protected delegate void AsyncTaskDelegate(HttpContext context);

        #region IHttpAsyncHandler Members

        public WordFileHandler()
        {
            this.del = new AsyncTaskDelegate(ProcessRequest);
        }

        public IAsyncResult BeginProcessRequest(HttpContext context, AsyncCallback cb, object extraData)
        {
            // Store context
            _context = context;
            return del.BeginInvoke(context, cb, extraData);
        }

        public void EndProcessRequest(IAsyncResult result)
        {
            this.del.EndInvoke(result);
        }

        #endregion

        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            HttpResponse resp = context.Response;
            resp.Clear();
            int workItemId = 0;
            if (Int32.TryParse(context.Request.QueryString["wi"], out workItemId))
            {
                MemoryStream ms = null;
                using (WorkItemReportService.ReportClient client = new WorkItemReportService.ReportClient())
                {
                    byte[] resultFile = client.GenerateWorkReport(
                        new Uri(ConfigurationManager.AppSettings["serverUri"]),
                        workItemId,
                        ConfigurationManager.AppSettings["wordTemplate"]);
                    ms = new MemoryStream(resultFile);
                }

                resp.ContentType = "application/octet-stream";
                resp.AddHeader("content-disposition", String.Format("attachment;filename=RelatorioSimples_WI-{0}.docx", workItemId));
                resp.Buffer = true;                
                ms.WriteTo(resp.OutputStream);
                resp.End();
            }
        }

        #endregion
    }
}

ItemCommand in the repeater:

if (e.CommandName.Equals("WordExport"))
{
    string uri = HttpContext.Current.Request.RawUrl;
    string url = string.Format("{0}/WordReport.dohx?wi={1}",
    uri.Substring(0, uri.LastIndexOf("/")), wivdata.SystemID);
    Response.Redirect(url);
}

Aspx Page (I pasted it all since I didn't figure out what was relevant and what wasn't):

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="~/ListaDeAtividadesPage.aspx.cs"
    MasterPageFile="~/_layouts/customapplication.master" Inherits="PublishVersionControlWebControl.ListaDeAtividadesPage, PublishVersionControlWebControl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=78508f22b73cda2b" %>

<%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <link rel='stylesheet' text='text/css' href='/_layouts/Extensions/Versioning/css/style.css' />
    <script src="/_layouts/Extensions/Versioning/js/jquery.tools.min.js" type="text/javascript"></script>
    <script src="/_layouts/Extensions/Versioning/js/jquery.corner.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderPageImage" runat="server">
    <img width="145" height="54" alt="Dashboard" src="/_layouts/Microsoft.TeamFoundation/images/notes.png" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
    runat="server">
    <asp:Literal ID="TitleContent" runat="server"></asp:Literal>
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <script type="text/javascript">
        _spOriginalFormAction = document.forms[0].action;
        _spSuppressFormOnSubmitWrapper = true;  
    </script>
    <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="updPanel">
        <ProgressTemplate >
            <div class="follower">
            <asp:Image ID="imgUpdate" CssClass="follower" ImageUrl="/_layouts/Extensions/Versioning/img/ui/ajax-loader.gif"
                runat="server" />
                <span class="follower">Carregando...</span>
            </div>
        </ProgressTemplate>
    </asp:UpdateProgress>
    <div>
        <asp:UpdatePanel ID="updPanel" runat="server">
            <ContentTemplate>
                <asp:Literal ID="tooltipScript" runat="server" />
                <div class="buttonBar">
                    <hr style="color: #426DA8;" />
                    <asp:Button CssClass="specific" ID="btnUpdateWI" Text="Atualiza WIs da Lista" runat="server"
                        UseSubmitBehavior="false" />
                    <asp:Button CssClass="specific" ID="btnRelatorioScripts" Text="Relatório de Scripts / ZIPs"
                        runat="server" />
                    <asp:Button CssClass="specific" ID="Button1" Text="Relatório de Publicações" runat="server" />
                    <asp:Button CssClass="generic" ID="btnVolta" Text="Volta ao Menu de Versões" runat="server" />
                    <hr style="color: #426DA8;" />
                </div>
                <asp:Repeater ID="rptListaAtividades" runat="server">
                    <HeaderTemplate>
                        <asp:Label ID="comentarioHeader" runat="server"/>
                        <h3>
                            <b class="rollback">Rollback</b> | <b class="emteste">Em Teste</b> | <b class="aindanaoincluido">
                                Ainda não Incluído</b> | <b class="parcialmenteok">Atividade Parcialmente OK</b>
                            | <b class="todosok">Atividade OK em Todas as Lojas</b> | <b class="parcpublicado">Parcialmente Publicada</b> | <b class="publicado">Atividade
                                Publicada</b>
                        </h3>   
                    </HeaderTemplate>
                    <ItemTemplate>
                        <div class="item" style="display: inline-block; font-size: 12px">
                            <asp:ImageButton ToolTip="Gerar Relatório Word" ImageUrl="/_layouts/Extensions/Versioning/img/wordexport.png"
                                CommandName="WordExport" ID="btnWordExport" CssClass="itembutton" runat="server" />
                            <asp:ImageButton ToolTip="Marcar como Rollback" ImageUrl="/_layouts/Extensions/Versioning/img/rollback.png"
                                CommandName="MarkAsRollback" ID="btnItemRollback" CssClass="itembutton" runat="server" />
                            <asp:ImageButton ToolTip="Esta atividade possui código. Clique para sinalizar como apenas procedure/config"
                                ImageUrl="/_layouts/Extensions/Versioning/img/code.png" CommandName="MarkAsProc"
                                ID="btnItemProc" CssClass="itembutton" runat="server" />
                            <asp:Image ToolTip="Esta atividade não possui scripts de banco/zips." ImageUrl="/_layouts/Extensions/Versioning/img/noscript.png"
                                runat="server" CssClass="itembutton" ID="btnItemScript" />
                            <asp:Label ID="labelWI" Text="" runat="server"></asp:Label>
                            <asp:Literal ID="tooltip" runat="server" />
                            <asp:Label ID="labelState" Text="" runat="server"></asp:Label>
                            <span style="color: #4A82CB">
                                <%# DataBinder.Eval(Container.DataItem, "SystemAssignedTo") %>
                                - </span><span style="color: Navy">
                                    <%# DataBinder.Eval(Container.DataItem, "SystemTitle") %>
                                </span>
                            <asp:HiddenField ID="workItemID" runat="server" />
                        </div>
                        <hr class="item" noshade style="color: #4CBDCB; height: 2px; background-color: #4CBDCB" />
                    </ItemTemplate>
                </asp:Repeater>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
</asp:Content>

Other details:

  • It's a layouts page in WSS 3.0
  • I'm not sure the update panel is where it should be

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

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

发布评论

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

评论(1

执着的年纪 2025-01-05 12:07:43

您无法从 updatepanel 内部的调用中调用 Response.Redirect(url) 。

通过此重定向,您会破坏视图状态,并且永远不会返回 updatepanel 询问的信息。为您的下载链接找到其他方法,或删除 updatepanel。

了解 ajax 和 UpdatePanel 的工作原理。你发送一个ajax请求,UpdatePanel等待应答数据,而你从来没有发送给他,所以指示器仍然永远等待。但是,在您发表帖子后,您会破坏视图状态,并且在您的第二篇帖子中,您将出现 javascript 错误。

一些可能的解决方案是在回发后渲染 JavaScript 以进行重定向,但使用 JavaScript 函数调用。

You can not call the Response.Redirect(url) from call inside of an updatepanel.

With this redirect you break the viewstate, and you never return the informations that updatepanel ask. Find some other way for your download link, or remove updatepanel.

Understand how ajax and UpdatePanel work. You send an ajax request, and UpdatePanel wait for the answer data, and you never send it to him, so the indicator still wait for ever. But after you have made a post you break the viewstate, and on your second post you going to have javascript errors.

Some possible solution is to render a javascript after the postback to make the redirect but with javascript function call.

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