0

我在互联网上搜索了将近 2 天以找到解决方案,但还没有任何效果。

我在一个页面上有 2 个用户控件。首先包含 AsyncFileUpload:

 <cc1:AsyncFileUpload runat="server" ID="fuExcelUploader" Width="400px" 
                                UploadingBackColor="#CCFFFF" ThrobberID="myThrobber" 
                                CompleteBackColor="#CEF6CE" />

第二个有一个带有下载按钮(excel文件)的模板字段的gridview

    <asp:TemplateField HeaderText="Report with errors" ItemStyle-HorizontalAlign="Center">
                        <ItemTemplate>
                                  <asp:LinkButton id="lbError"   CommandName="ErrorClick" runat="server"  CommandArgument='<%# Eval("Report.Id") %>'  ValidationGroup="other2357"><asp:Image ID="imgReport" runat="server"  
ImageUrl="~/App_Themes/Default/Images/icons/page_excel.png" ImageAlign="Middle"   Visible='<%# Convert.ToInt32(Eval("Report.Id")) > 0 %>' /></asp:LinkButton>

                         </ItemTemplate>
                    </asp:TemplateField>

在 RowCommand 如果 e.CommandName = ErrorClicked 我有这样一段代码用于下载文件

Response.Clear();
                Response.Buffer = true;
                Response.AddHeader(
                    "Content-Disposition", string.Format("attachment; filename={0}", "Error_report_" + this.ErrorClicked + ".xlsx"));
                HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats";
               // Response.Cache.SetCacheability(HttpCacheability.Private);
                Response.BinaryWrite(value); //value is byte[];
                Response.End();

它完美运行我可以使用 asyncfileupload 上传文件,然后通过单击 gridview 等上的图标下载报告,但是有一个问题。

每当我单击 gridview 上的下载图标时,会弹出下载文件对话框,我可以保存/打开/取消,但无论我做什么,在我尝试使用 asyncfileupload 上传新文件后,都会使用相同的“ErrorClick”CommandName 触发相同的 RowCommand 事件和CommandArgument,所以我要再次下载带有文件的窗口(并且页面被锁定)。这可能是因为 linkbutton 和 asyncfileupload 都没有刷新整个页面(它是相同的回发吗?)。

您是否知道为什么在使用 asyncfileupload 控件上传期间会触发 rowcommand 或如何解决该问题。在这种情况下,我不使用 udpatepanels。

4

1 回答 1

-1


OnRowComand 事件在您单击 Link 按钮并在处理上传后触发。注册两次下载代码会发生错误。
LinkBut​​ton 中的“href”脚本会以某种方式影响此结果。我使用了 ImageButton 来触发下载,并使用 LinkBut​​ton 来执行 ImageButton 的事件点击。

ASPX

ImageButton -> Style="display: none;"


ASPX.CS - 行数据绑定

LinkButton.Attributes.Add("OnClick", "$(document.getElementById('" + ImageButton.ClientID + "')).click(); return false;");

对不起,我的英语很糟糕。我用谷歌翻译。

于 2014-09-15T19:48:50.403 回答