AjaxFileUpload一旦选择就会自动上传文件 [英] AjaxFileUpload automatically upload file once selected

查看:482
本文介绍了AjaxFileUpload一旦选择就会自动上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个标准的AjaxFileUpload控件

I have a standard AjaxFileUpload control

<asp:AjaxFileUpload ID="upManager" CssClass="fileUpload" runat="server" OnUploadComplete="upManager_UploadComplete" />

不必选择上传,我只希望文件选择后自动上传文件。有办法吗?

And instead of them having to press Upload, I just want the file to upload automatically once they have selected the file. Is there a way to do this?

推荐答案

将此脚本的引用添加到脚本 ToolkitScriptManager 控件的集合,或者只是将其放在页面的底部:

Add reference to this script to Scripts collection of ToolkitScriptManager control or just put it at very bottom of page:

var legacyAddToQueue = Sys.Extended.UI.AjaxFileUpload.prototype._addToQueue;
Sys.Extended.UI.AjaxFileUpload.prototype._addToQueue = function(element){
    legacyAddToQueue.apply(this, [element]);
    this._doUpload();
}

在此页面上的控制台运行良好: AjaxFileUpload演示

Works well from console at this page: AjaxFileUpload Demonstration

另外,我认为最好调整ACT源并将新属性(如 UploadAutomatically )添加到此控件中。让我知道您是否愿意使用此选项,并且需要有关如何聘请此类人员的更多详细信息

Also, in my opinion should be better to tweak ACT sources and add new property like UploadAutomatically to this control. Let me know if you'll prefer this option and need additional details about how to to such staff

更新:请针对新的AjaxFileUpload尝试使用此脚本(无论新旧都必须使用)版本,但尚未测试)

UPDATED: try this script for new AjaxFileUpload (must work for new and old versions but not tested yet)

if (Sys.Extended.UI.AjaxFileUpload.prototype._addToQueue) {
    var legacyAddToQueue = Sys.Extended.UI.AjaxFileUpload.prototype._addToQueue;
    Sys.Extended.UI.AjaxFileUpload.prototype._addToQueue = function (element) {
        legacyAddToQueue.apply(this, [element]);
        this._doUpload();
    };
}else if(Sys.Extended.UI.AjaxFileUpload.Control){
    var legacyaddFileToQueue = Sys.Extended.UI.AjaxFileUpload.Control.prototype.addFileToQueue;
    Sys.Extended.UI.AjaxFileUpload.Control.prototype.addFileToQueue = function(fileItem){
        if(legacyaddFileToQueue.apply(this, [fileItem])){
            this._isUploading = true;
            this.enableControls(this._isUploading);
            this._processor.startUpload();
        }
    };
}

这篇关于AjaxFileUpload一旦选择就会自动上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆