我有一个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(我粘贴了所有内容,因为我没有弄清楚什么是相关的,什么不相关):
<%@ 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>
其他细节:
答案 0 :(得分:1)
您无法通过更新面板内的来电拨打Response.Redirect(url)
。
通过此重定向,您可以中断视图状态,并且永远不会返回updatepanel要求的信息。找到下载链接的其他方式,或删除updatepanel。
了解ajax和UpdatePanel的工作原理。你发送一个ajax请求,UpdatePanel等待答案数据,你永远不会发送给他,所以指标仍然等待。但是在你发帖后你打破了viewstate,在你的第二篇文章中你会出现javascript错误。
一些可能的解决方案是在回发后呈现javascript以进行重定向但是使用javascript函数调用。