I want to show a message when ajaxToolkit:AjaxFile

2019-02-18 11:03发布

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

2条回答
冷血范
2楼-- · 2019-02-18 11:27

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.

查看更多
可以哭但决不认输i
3楼-- · 2019-02-18 11:48

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

查看更多
登录 后发表回答