ASP.NET AJAX AsyncFileUpload UploadedComplete不会触发[重复]

时间:2022-02-10 15:12:58

This question already has an answer here:

这个问题在这里已有答案:

Thanks for your attention in advance, I'm new to ASP.NET AJAX AsyncFileUpload so I've created an aspx page to test it but it seems there's some bug with that control because the server side UploadedComplete event does not fire.

感谢您提前注意,我是ASP.NET AJAX AsyncFileUpload的新手,所以我创建了一个aspx页面来测试它,但似乎该控件存在一些错误,因为服务器端的UploadedComplete事件不会触发。

the aspx :

aspx:

<form id="form1" runat="server" method="post" enctype="multipart/form-data">
<div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <cc1:AsyncFileUpload ID="AsyncFileUpload1" runat="server" OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </ContentTemplate>
    </asp:UpdatePanel>
</div>
</form>

and the code behind

和背后的代码

public partial class Tester : System.Web.UI.Page
{
    protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        this.Label1.Text = "OK";
    }
}

would anyone please let me know why it does not work? Thanks a lot

有谁请让我知道为什么它不起作用?非常感谢

2 个解决方案

#1


7  

When you use AsyncFileUpload you must set the right params in the "form" tag, that is placed in your Page or MasterPage:

当您使用AsyncFileUpload时,您必须在“表单”标记中设置正确的参数,该标记位于您的Page或MasterPage中:

 <form id="form1" runat="server" enctype="multipart/form-data" method="post">

If you don't set the right enctype enctype="multipart/form-data" method UploadedComplete will never fire, and you won't be able to get FileUpload.FileBytes since FileUpload.HasFile returns true only during UploadedComplete execution.

如果未设置正确的enctype enctype =“multipart / form-data”方法,则UploadedComplete将永远不会触发,并且您将无法获取FileUpload.FileBytes,因为FileUpload.HasFile仅在UploadedComplete执行期间返回true。

Besides, prevoius versions of AsyncFileUpload didn't work on Chrome. Version from 4.1.50731.0 solved the problem.

此外,prevoius版本的AsyncFileUpload在Chrome上不起作用。 4.1.50731.0版本解决了这个问题。

#2


0  

Typically you don't want to use an updatepanel and uploadfile control together. It boils down to the same reasons you can't set the file of an uploadfile, security.

通常,您不希望同时使用updatepanel和uploadfile控件。归结为您无法设置上传文件的安全性的相同原因。

#1


7  

When you use AsyncFileUpload you must set the right params in the "form" tag, that is placed in your Page or MasterPage:

当您使用AsyncFileUpload时,您必须在“表单”标记中设置正确的参数,该标记位于您的Page或MasterPage中:

 <form id="form1" runat="server" enctype="multipart/form-data" method="post">

If you don't set the right enctype enctype="multipart/form-data" method UploadedComplete will never fire, and you won't be able to get FileUpload.FileBytes since FileUpload.HasFile returns true only during UploadedComplete execution.

如果未设置正确的enctype enctype =“multipart / form-data”方法,则UploadedComplete将永远不会触发,并且您将无法获取FileUpload.FileBytes,因为FileUpload.HasFile仅在UploadedComplete执行期间返回true。

Besides, prevoius versions of AsyncFileUpload didn't work on Chrome. Version from 4.1.50731.0 solved the problem.

此外,prevoius版本的AsyncFileUpload在Chrome上不起作用。 4.1.50731.0版本解决了这个问题。

#2


0  

Typically you don't want to use an updatepanel and uploadfile control together. It boils down to the same reasons you can't set the file of an uploadfile, security.

通常,您不希望同时使用updatepanel和uploadfile控件。归结为您无法设置上传文件的安全性的相同原因。