ajaxToolkit:AjaxFileUpload自动上传

时间:2014-02-06 22:21:51

标签: c# html asp.net ajax ajaxcontroltoolkit

我使用ajaxToolkit:AjaxFileUpload。当用户点击开始上传按钮时,它可以工作。我想更改它,以便在选择或拖放文件时,上传器会自动开始上传。我该怎么办?我的代码是:

<ajaxToolkit:ToolkitScriptManager runat="Server" EnablePartialRendering="true" ID="ScriptManager1" />

<ajaxToolkit:AjaxFileUpload ID="AjaxFileUploader"  OnUploadComplete="AjaxFileUploader_UploadComplete" runat="server"  />

protected void AjaxFileUploader_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
    AjaxFileUploader.SaveAs(MapPath("~/UploadedFiles/" + e.FileName));
}

1 个答案:

答案 0 :(得分:0)

让您的上传组件使用“FileAttachmentUpload”类 然后使用下面的jQuery。

$(".FileAttachmentUpload").change(function () {
            $(".FileAttachmentUpload .ajax__fileupload_uploadbutton").click();
        });
        $(".ajax__fileupload_dropzone").on('drop', function () {
            $(".ajax__fileupload_uploadbutton").click();
        });