【问题标题】:I want to show a message when ajaxToolkit:AjaxFileUpload start uploading, is there a way to do this我想在 ajaxToolkit:AjaxFileUpload 开始上传时显示一条消息,有没有办法做到这一点
【发布时间】:2012-07-26 00:44:06
【问题描述】:

我想在 ajaxToolkit:AjaxFileUpload 开始上传时给我一条消息,有没有办法做到这一点

【问题讨论】:

标签: javascript jquery asp.net ajaxcontroltoolkit


【解决方案1】:

默认情况下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();
}

而不是构建解决方案并享受新功能。

【讨论】:

  • +1 起初,由于您的显示图像,我犹豫是否要为您投票,但后来我对其进行了测试。
  • 你到底测试了什么?我发布的图片或解决方案? :)
【解决方案2】:

在 AjaxControlToolkit 的当前版本(2013 年 12 月发布版本 7.1213)中,此事件可用,无需任何源代码修改。

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

【讨论】:

    猜你喜欢
    • 2021-07-09
    • 2011-10-04
    • 2011-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-23
    相关资源
    最近更新 更多