本文介绍了我想在 ajaxToolkit:AjaxFileUpload 开始上传时显示一条消息,有没有办法做到这一点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

默认情况下 AjaxFileUpload 没有这样的事件.但由于 AjaxControlToolkit 是一个开源库,您可以自己添加它.从此页面下载最近的库源:源代码,找出 AjaxFileUpload 控件源(/Server/AjaxControlToolkit/AjaxFileUpload 文件夹)并将以下代码添加到 AjaxFileUpload.cs 文件中:

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;
    }
}

之后,修改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();
}

比构建解决方案并享受新功能.

Than build solution and enjoy with new functionality.

这篇关于我想在 ajaxToolkit:AjaxFileUpload 开始上传时显示一条消息,有没有办法做到这一点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 13:18