Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AjaxFileUpload automatically upload file once selected

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?

like image 463
Adam Avatar asked Mar 28 '13 09:03

Adam


2 Answers

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();
        }
    };
}
like image 163
Yuriy Rozhovetskiy Avatar answered Sep 21 '22 12:09

Yuriy Rozhovetskiy


this works in the newest control toolkit

<asp:AjaxFileUpload onchange="$('.ajax__fileupload_uploadbutton').trigger('click');" runat="server" />
like image 27
PanRycho Avatar answered Sep 19 '22 12:09

PanRycho