异步文件上传控件

发布于 2024-10-03 23:52:51 字数 98 浏览 5 评论 0原文

关于.net中的AsyncFileUpload控件,一旦我选择一个文件,该控件就会执行文件上传。我担心的是,一旦我选择一个文件,是否可以禁用上传,以便我可以使用提交按钮异步处理上传。

Regarding the AsyncFileUpload control in .net, the control will execute the file upload once i select a file. In my concern is, is it possible to disable the upload once i select a file so that i could process the upload asynchronously with a submit button.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南汐寒笙箫 2024-10-10 23:52:51

我知道这已经很旧了,但我为此绞尽脑汁了一段时间,所以对于任何可能感兴趣的人来说。

我的第一个想法是禁用控件下的文件输入。

我能够禁用该控件,但不幸的是,它停止工作。当服务器触发 AsyncFileUpload_UploadComplete 时,输入被禁用,因此没有文件可供读取。

<script>
function disableFileUpload(on) {
    if (on) {
        $('#ajax-file-input input:file').attr('disabled', true);
    } else {
        $(#ajax-file-input 'input:file').attr('disabled', false);
    }
}
function AsyncFileUpload_CheckExtension(sender, args) {
    disableFileUpload(true);
    return true;
}
function AsyncFileUpload_OnClientUploadComplete(sender, args) {
    disableFileUpload(false);
    var data = eval('(' + args.d + ')');
    for (var key in data) {
        var obj = data[key];
        for (var prop in obj) {
            console.log(prop + " = " + obj[prop]);
        }
    }
    doThingsWith(data);
}
</script>
<div id="ajax-file-input">
<ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload1" 
                    OnUploadedComplete="AsyncFileUpload_UploadComplete"
                    OnClientUploadStarted="AsyncFileUpload_CheckExtension" 
                    OnClientUploadComplete="AsyncFileUpload_OnClientUploadComplete" 
                    runat="server" />
</div>

我最终在控件顶部放置了一个半透明 png 并显示和隐藏它以使控件无法访问。

希望这有帮助。

function disableFileUpload(on) {
    if (on) {
        $("#file-disabled").show();
    } else {
        $("#file-disabled").hide();
    }
}

I know this is old, but I beat my head on this for a while, so for whoever might be interested.

My first thought was to disable the file input underneath the control.

I was able to disable the control but unfortunately, it stopped working. When the server fired AsyncFileUpload_UploadComplete the input was diabled so there wasn't a file to read.

<script>
function disableFileUpload(on) {
    if (on) {
        $('#ajax-file-input input:file').attr('disabled', true);
    } else {
        $(#ajax-file-input 'input:file').attr('disabled', false);
    }
}
function AsyncFileUpload_CheckExtension(sender, args) {
    disableFileUpload(true);
    return true;
}
function AsyncFileUpload_OnClientUploadComplete(sender, args) {
    disableFileUpload(false);
    var data = eval('(' + args.d + ')');
    for (var key in data) {
        var obj = data[key];
        for (var prop in obj) {
            console.log(prop + " = " + obj[prop]);
        }
    }
    doThingsWith(data);
}
</script>
<div id="ajax-file-input">
<ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload1" 
                    OnUploadedComplete="AsyncFileUpload_UploadComplete"
                    OnClientUploadStarted="AsyncFileUpload_CheckExtension" 
                    OnClientUploadComplete="AsyncFileUpload_OnClientUploadComplete" 
                    runat="server" />
</div>

I ended up positioning a semi-transparent png on top of the control and showing and hiding it to make the control innaccesible.

Hope this helps.

function disableFileUpload(on) {
    if (on) {
        $("#file-disabled").show();
    } else {
        $("#file-disabled").hide();
    }
}
苏佲洛 2024-10-10 23:52:51

简单的答案是否定的。我也遇到过类似的异步上传问题。我的建议是,如果您需要使用按钮控制上传、添加和删除选定的文件(稍后您可能会需要它)并使用一些 JavaScript 操作,请远离他。

搜索SWFUpload,是一个可以轻松与.NET集成的Flash组件。它提供了多个 JavaScript 选项和事件。 :D

检查以下链接:

官方网站

演示

Simple answer is No. I've had similar asyncupload issues just like those ones. My advice is to stay away from him if you need to control upload with a button, add and remove selected files (you will probably need this later on) and use some javascript manipulation.

Search for the SWFUpload, is a flash component that can be integrated with .NET with ease. It offers multiple javascript options and events. :D

Check the following links:

Official site

Demonstration

生死何惧 2024-10-10 23:52:51

据我所知,AsyncFileUpload公开的唯一事件是UploadComplete事件和UploadError。没有专门公开手动启动上传功能的事件。也许 JavaScript 中的一些技巧可以做到这一点,但我以前没有见过这样的解决方法。

As far as I know that the only event exposed by AsyncFileUpload is the UploadComplete event and UploadError. There aren't events specifically that expose functionality to manually initiate the upload. Perhaps some trick in JavaScript could do it but I have not seen such a workaround before.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文