javascript - 我想在 ajaxToolkit :AjaxFileUpload start uploading, 有办法做到这一点时显示一条消息

标签 javascript jquery asp.net ajaxcontroltoolkit

我想在 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/

相关文章:

javascript - 正则表达式适用于在线测试器,不适用于 Typescript Regexp

jquery - 为什么我的粘性菜单在更改到位置 :fixed 时向左跳转

jquery - 使用 jQuery 更改多个背景图像

.net - 分析 elmah 日志

c# - 如何使用 ASP.Net MVC URL 路由为所有操作添加前缀?

javascript - 未捕获的类型错误 : Cannot read property 'display' of undefined

javascript - addClass 一段时间并使用 javascript 删除它

javascript - Ajax 数据不会 $_POST 到 php 页面

jquery - 动态 jquery 对话框弹出窗口

c# - 创建一个新的 MailAddress 会产生 "The specified string is not in the form required for an e-mail address",尽管它的格式是正确的