0
votes

I've searched for almost 2 days on the internet to find solution but nothing works yet.

I have 2 user controls on a page. First contains AsyncFileUpload:

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

and the second has a gridview with such templatefield with download button(excel file)

    <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>

In the RowCommand if e.CommandName = ErrorClicked I have such piece of code for downloading file

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();

It works perfect I can upload files with asyncfileupload then download reports by clicking icons on gridview etc. , but there is one problem.

Whenever I click on download icon on gridview, the download file dialog pops up, I can save/open/cancel but whatever I do, after I try to upload new file with asyncfileupload the same RowCommand event is fired with same 'ErrorClick' CommandName and CommandArgument, so I am getting that window with file to download again (and page is locked). It might be because neither linkbutton nor asyncfileupload refresh whole page (is it the same postback?).

Do you have any idea why the rowcommand is fired during uploading with asyncfileupload control or how to solve that problem. I don't use udpatepanels in this case.

1
Is the AsyncFileUpload within an UpdatePanel that does not have the UpdateMode set to Conditional?Lloyd
No, it is outside updatepanel. Tried to add both controls to updatepanel, but problem still exists.Kostrzak
Is the UpdatePanels UpdateMode set to conditional?Lloyd
No, it is ou.. I mean there is no Updatepanels on that page. Both controls don't need them. Previously they were in updatepanel with udpatemode=always, but I doubt it matters :)Kostrzak

1 Answers

-1
votes


The OnRowComand event is fired when you click the Linkbutton and after processing the upload. An error occurs by registering twice the download code.
The script of the "href" in the LinkButton somehow influences this result. I used a ImageButton to trigger the download, and the LinkButton to execute the event click of ImageButton.

ASPX

the ImageButton -> Style="display: none;"


ASPX.CS - RowDataBound

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

Sorry, my English is horrible. I use google Translate.