I want to show a message when ajaxToolkit:AjaxFileUpload start uploading, is there a way to do this

后端 未结 2 1233
既然无缘
既然无缘 2021-01-13 13:13

I want to a message when ajaxToolkit:AjaxFileUpload start uploading, is there a way to do this

相关标签:
2条回答
  • 2021-01-13 14:02

    By default AjaxFileUpload doesn't have such event. But as the AjaxControlToolkit is an open-source library, you can add it yourself. Download the recent library sources from this page: source codes, find out AjaxFileUpload control sources (/Server/AjaxControlToolkit/AjaxFileUpload folder) and add code below to the AjaxFileUpload.cs file:

    [DefaultValue("")]
    [Category("Behavior")]
    [ExtenderControlEvent]
    [ClientPropertyName("uploadStarted")]
    public string OnClientUploadStarted
    {
        get
        {
            return (string)(ViewState["OnClientUploadStarted"] ?? string.Empty);
        }
        set
        {
            ViewState["OnClientUploadStarted"] = value;
        }
    }
    

    after that, modify AjaxFileUpload.pre.js file:

    // insert this code right after the _raiseUploadComplete method
    add_uploadStarted: function (handler) {
        this.get_events().addHandler("uploadStarted", handler);
    },
    
    remove_uploadStarted: function (handler) {
        this.get_events().removeHandler("uploadStarted", handler);
    },
    
    _raiseUploadStarted: function () {
        var eh = this.get_events().getHandler("uploadStarted");
        if (eh) {
            eh(this, Sys.EventArgs.Empty);
        }
    },
    
    // modify the _doUpload method
    _doUpload: function () {
    
        if (!this._filesInQueue.length || this._filesInQueue.length < 1)
            return;
    
        this._raiseUploadStarted();
    
        this._currentQueueIndex = -1;
        if (!this._isFileApiSupports)
            this._createIframe();
    
        this._processNextFile();
    }
    

    Than build solution and enjoy with new functionality.

    0 讨论(0)
  • 2021-01-13 14:07

    In current version (December 2013 Release Version 7.1213) of AjaxControlToolkit this event is availbale without any need for any source code modifications.

    http://ajaxcontroltoolkit.codeplex.com/SourceControl/latest#Server/AjaxControlToolkit/AjaxFileUpload/AjaxFileUpload.cs

    0 讨论(0)
提交回复
热议问题