asp.net AsyncFileUpload-显示上传文件列表
我使用ajaxtoolkit AsyncFileUpload,并且想要显示上载文件的列表,最后的错误并处理转发器itemCommand来删除上载的文件.
I use ajaxtoolkit AsyncFileUpload and I want to show list of uploaded files, a last error and handle repeater itemCommand to delete uploaded file.
<asp:AsyncFileUpload ID="uploader1"
runat="server"
OnUploadedComplete="AsyncFileUpload1_UploadComplete"
OnClientUploadError="uploadError"
OnClientUploadStarted="StartUpload"
OnClientUploadComplete="UploadComplete"
CompleteBackColor="Lime"
UploaderStyle="Modern"
ErrorBackColor="Red"
UploadingBackColor="#66CCFF"
ClientIDMode="AutoID"
EnableViewState="true" />
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Label ID="lblError" runat="server" ForeColor="Red" Visible="false" />
<asp:Repeater ID="rptAttachments"
runat="server"
OnItemCommand="Uploader_ItemCommand">
<ItemTemplate>
<a href='#'><%#Eval("Filename") %></a>
<asp:LinkButton ID="lnkDelete"
runat="server" Text="Удалить"
CommandName="DeleteAttachment"
CommandArgument='<%#Eval("FileName") %>'
/>
</ItemTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="uploader1" EventName="UploadedComplete" />
</Triggers>
</asp:UpdatePanel>
void AsyncFileUpload1_UploadComplete(object sender, AsyncFileUploadEventArgs e)
{
if (e.state == AsyncFileUploadState.Success)
{
if (!Facade.Attachment.UploadAttachment(attachment))
ShowErrorMessage("File already exists");
else
BindAttachments();
}
}
void BindAttachments()
{
rptAttachments.DataSource = Facade.Attachment.GetAttachments(AttachmentId2);
rptAttachments.DataBind();
}
事件AsyncFileUpload1_UploadComplete引起了,但是没有任何反应.
The event AsyncFileUpload1_UploadComplete causes, but nothing happens.
问题是OnUploadedComplete
事件是异步的,您无法在页面中进行任何更改.后来我遇到了此类问题,并且您没有看到任何答案. ..
我为我找到了一种解决方法.我在服务器处理程序cookie中设置了所需的信息,然后在客户端函数中读取它并执行适当的操作.
例如,您可以尝试在客户端获取Cookie之后,发送请求以刷新页面.
The matter is OnUploadedComplete
event is asynchronous and you can't make any changes in page. I had such problem later and as you can see, no answers...
I've found a workaround for me. I set in the server handler cookies with information, that I need and then read it in the client function and do appropriate action.
You can try, for example, after getting cookies on client side, send request to refresh page.