ASP.NET文件上传:一旦选择了一个文件如何自动回发? [英] ASP.NET FileUpload: how to automatically post back once a file is selected?

查看:84
本文介绍了ASP.NET文件上传:一旦选择了一个文件如何自动回发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个ASP.NET应用程序,我有必要回发一个文件选择在FileUpload控件后服务器,而不必让用户明确地点击提交按钮。这可能吗?如果是这样,怎么样?

I am working on a ASP.NET app and i have a need to post back to the server after a file is chosen in a FileUpload control without having to have the user explicitly click a 'submit' button. Is this possible? and if so, how?

推荐答案

我假设你想上传马上开始。如果是这样,你应该作出反应,变更事件的JavaScript,并简单地使之提交表单。

I'm assuming you want to make the upload start right away. If so, you should react to the change event in JavaScript, and simply make it submit the form.

<!-- HTML code --->
<input 
  type="file" 
  onchange="if (confirm('Upload ' + this.value + '?')) this.form.submit();"
>

询问用户确认是值得推荐的,所以一直停留在这个过程的控制,并可以取消,如果他们不小心选择了错误的文件。

Asking the users for confirmation is recommendable, so they stay in control of the process and can cancel if they chose the wrong file by accident.

这篇关于ASP.NET文件上传:一旦选择了一个文件如何自动回发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆