【问题标题】:Why AsyncFileUpload fires RowCommand event on gridview?为什么 AsyncFileUpload 在 gridview 上触发 RowCommand 事件?
【发布时间】:2012-03-12 10:54:33
【问题描述】:

我在互联网上搜索了将近 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>

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

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 上传新文件后,相同的 RowCommand 事件会以相同的“ErrorClick”触发' CommandName 和 CommandArgument,所以我要再次下载带有文件的窗口(并且页面被锁定)。可能是因为 linkbutton 和 asyncfileupload 都没有刷新整个页面(是相同的回发吗?)。

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

【问题讨论】:

  • AsyncFileUpload 是否位于未将 UpdateMode 设置为 Conditional 的 UpdatePanel 中?
  • 不,它在更新面板之外。尝试将两个控件都添加到更新面板,但问题仍然存在。
  • UpdatePanels UpdateMode 是否设置为有条件的?
  • 不,是的。我的意思是那个页面上没有更新面板。两个控件都不需要它们。以前他们在更新面板中使用 udpatemode=always,但我怀疑这很重要:)

标签: c# asp.net events postback asyncfileupload


【解决方案1】:


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

ASPX

ImageButton -> Style="display: none;"


ASPX.CS - RowDataBound

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

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

【讨论】:

    猜你喜欢
    • 2017-11-11
    • 2012-01-19
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多