c# - AsyncFileUpload postback causes double upload -
i implemented asyncfileupload
control on web page. web page requires uploaded files appear in gridview
.
gridview
contains following columns: "file name", "confidential" check box, , "remove" button remove uploaded file.
since asyncfileupload
postback not full page postback, need "force" postback on onclientuploadcomplete
event of asyncfileupload control in order render gridview after uploading file.
in onclientuploadcompleteevent
, use javascript call __dopostback
. in postback, bind gridview , display file information (i don’t re-save file).
the problem: on asyncfileupload
’s first “partial” postback, file uploaded, expected. on second postback force __dopostback
, file re-uploaded.
can verify using google chrome, displays upload progress. behaviour follows:
- after selecting file, progress increments 0% 100% , file uploaded.
- after this, __dopostback
executes, , can see upload progress increment again 0% 100%.
how can make sure gridview populated, file not uploaded twice?
i attached sample solution contains issue: https://www.yousendit.com/download/mzzfc2zbndrryun4dnc9pq
maybe ugly, works:
1) add css-hidden asp:button bellow asp:asyncfileupload asyncfileupload1
control.
<asp:button runat="server" id="btnclick" text="update grid" style="display:none"/>
2) on page_load
method, remove if (request.params.get("__eventtarget") == "uploadpostback")
, put block in simple else
previous if
.
3) on asyncfileupload1_uploadedcomplete
function, remove if (request.params.get("__eventtarget") != "uploadpostback")
line, leave intact inside it.
4) aspx. put asp:updatepanel outside grid gridview1.
<asp:updatepanel runat="server" updatemode="conditional"> <triggers> <asp:asyncpostbacktrigger controlid="btnclick" eventname="click" /> </triggers> <contenttemplate> <asp:gridview id="gridview1" ... grid code remains same </asp:gridview> </contenttemplate> </asp:updatepanel>
5) last step change ajaxuploadcomplete
client-side javascript function make trigger postback. replace following:
function ajaxuploadcomplete() { var btnclick = document.getelementbyid("btnclick"); btnclick.click(); }
any file user selects uploaded once.
changes here meant made in ajaxupload.aspx & ajaxupload.aspx.cs of ajaxupload.zip.
Comments
Post a Comment