AjaxFileUpload 选择后自动上传文件 [英] AjaxFileUpload automatically upload file once selected

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

问题描述

我有一个标准的 AjaxFileUpload 控件

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

他们不必按上传,我只想在他们选择文件后自动上传文件.有没有办法做到这一点?

解决方案

将对此脚本的引用添加到 ToolkitScriptManager 控件的 Scripts 集合或将其放在最底部页面:

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

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

此外,我认为应该更好地调整 ACT 源并将诸如 UploadAutomatically 之类的新属性添加到此控件.让我知道您是否更喜欢此选项,并需要有关如何使用此类员工的更多详细信息

更新:为新的 AjaxFileUpload 尝试这个脚本(必须适用于新旧版本但尚未测试)

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

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?

解决方案

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();
}

Works well from console at this page: AjaxFileUpload Demonstration

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

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天全站免登陆