AsyncFileUpload回传导致双上传 [英] AsyncFileUpload postback causes double upload
问题描述
我实现了一个网页上的 AsyncFileUpload
控制。此网页需要上传的文件出现在的GridView
。
该的GridView
包含以下栏目:文件名的,保密的复选框,以及删除的按钮来删除上传的文件。
I implemented the AsyncFileUpload
control on a web page. This web page requires uploaded files to appear in a GridView
.
The GridView
contains the following columns: "File Name", "Confidential" Check Box, and a "Remove" button to remove the uploaded file.
由于 AsyncFileUpload
回传没有做的全页的回传,我需要逼回发的 OnClientUploadComplete
事件,以便上传文件后,呈现在GridView的AsyncFileUpload控制。
在 OnClientUploadCompleteEvent
,我使用JavaScript来调用 __ doPostBack
。在这回发,我只能绑定我的GridView和显示文件信息(我不要再保存文件)。
Since the AsyncFileUpload
postback does not do a full page postback, I need to "force" a postback on the OnClientUploadComplete
event of the AsyncFileUpload control in order to render the gridview after uploading a file.
In the OnClientUploadCompleteEvent
, I use javascript to call __doPostBack
. In this postback, I only bind my GridView and display the file information (I don’t re-save the file).
问题:在 AsyncFileUpload
第一个局部回传,该文件被上传成功,符合市场预期。在我与强制__ doPostBack
第二回传,该文件重新上传。
您可以通过使用谷歌浏览器,显示上传进度验证这一点。的行为如下:
- 选择文件后,进度增量从0%到100%,并且该文件被上传
。
- 在此之后, __ doPostBack
执行,你可以再次看到上传进度增量从0%到100%
The problem: On the AsyncFileUpload
’s first "partial" postback, the file is successfully uploaded, as expected. On the second postback that I force with __doPostBack
, the file is re-uploaded.
You can verify this by using Google Chrome, which displays the upload progress. The behaviour is as follows:
- After selecting the file, the progress increments from 0% to 100% and the file is uploaded.
- After this, the __doPostBack
executes, and you can see the upload progress increment again from 0% to 100%.
我怎样才能确保在GridView填充正常,但该文件没有上传过两次?
How can I make sure the Gridview is properly populated, but that the file is not uploaded twice?
我连接包含问题的样品溶液: https://www.yousendit.com/download/ MzZFc2ZBNDRrYUN4dnc9PQ
I attached a sample solution which contains the issue: https://www.yousendit.com/download/MzZFc2ZBNDRrYUN4dnc9PQ
推荐答案
也许难看,但作品:
1)
添加CSS隐藏的asp:按钮娄ASP:AsyncFileUpload AsyncFileUpload1
控制
1)
Add a css-hidden asp:Button bellow the asp:AsyncFileUpload AsyncFileUpload1
control.
<asp:Button runat="server" ID="btnClick" Text="Update grid" style="display:none"/>
2)
在的Page_Load
法,删除如果(Request.Params.Get(__ EVENTTARGET)==UploadPostback)
并把它挡在一个简单的其他
至previous 如果
。
2)
On the Page_Load
method, remove the if (Request.Params.Get("__EVENTTARGET") == "UploadPostback")
and put its block in a simple else
to the previous if
.
3)
在 AsyncFileUpload1_UploadedComplete
功能,还删除如果(Request.Params.Get(__ EVENTTARGET)!=UploadPostback)
行,但留下完整的一切,在它里面。
3)
On the AsyncFileUpload1_UploadedComplete
function, also remove the if (Request.Params.Get("__EVENTTARGET") != "UploadPostback")
line, but leave intact everything that was inside it.
4) 回到ASPX。将一个ASP:UpdatePanel中电网GridView1外
4) Back to the aspx. Put a asp:UpdatePanel outside the grid GridView1.
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnClick" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:GridView ID="GridView1" ...
YOUR GRID CODE REMAINS THE SAME
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
5)
最后一步是修改 AjaxUploadComplete
客户端的JavaScript功能,使之触发回发。
用以下替换它:
5)
The last step is to change the AjaxUploadComplete
client-side javascript function to make it trigger the postback.
Replace it with the following:
function AjaxUploadComplete() {
var btnClick = document.getElementById("btnClick");
btnClick.click();
}
用户选择上传一次的任何文件。
所有的变化在这里是为了在AjaxUpload.aspx和放大器来进行;您AjaxUpload.zip的AjaxUpload.aspx.cs。
Any file the user selects is uploaded only once.
All changes here are meant to be made in AjaxUpload.aspx & AjaxUpload.aspx.cs of your AjaxUpload.zip.
这篇关于AsyncFileUpload回传导致双上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!