我想在 ajaxToolkit:AjaxFileUpload 开始上传时收到一条消息,有没有办法做到这一点
最佳答案
默认 AjaxFileUpload
没有这样的事件。但由于 AjaxControlToolkit 是一个开源库,您可以自己添加它。从此页面下载最近的库资源:source codes , 找到 AjaxFileUpload 控件源(/Server/AjaxControlToolkit/AjaxFileUpload 文件夹)并将下面的代码添加到 AjaxFileUpload.cs 文件中:
[DefaultValue("")]
[Category("Behavior")]
[ExtenderControlEvent]
[ClientPropertyName("uploadStarted")]
public string OnClientUploadStarted
{
get
{
return (string)(ViewState["OnClientUploadStarted"] ?? string.Empty);
}
set
{
ViewState["OnClientUploadStarted"] = value;
}
}
之后,修改AjaxFileUpload.pre.js
文件:
// 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();
}
然后构建解决方案并享受新功能。
关于javascript - 我想在 ajaxToolkit :AjaxFileUpload start uploading, 有办法做到这一点时显示一条消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11686086/