如何防止回发时清除FileUpload控件? [英] How to prevent FileUpload control from clearing on postback?

查看:92
本文介绍了如何防止回发时清除FileUpload控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在FileUpload控件上遇到了一些麻烦,想知道我是否可以得到一些帮助.

I'm having some trouble with the FileUpload control and was wondering if I could get some help.

在我的页面上,我有一个FileUpload控件和一个下拉列表.

On my page I have a FileUpload control, and a drop down list.

因此,用户浏览到所需的文件,然后从下拉菜单中选择一个选项(这将启用某些也在页面上使用的复选框,具体取决于他们在下拉菜单中选择的内容).这将导致FileUpload控件变为空,现在用户必须再次浏览到他们想要的文件.

So the user browses to the file they want, and then select an option from the drop down (which enables some checkboxes that are also on the page for use, depending on what they select in the drop down). This causes the FileUpload control to become empty, and now the user must browse to the file they wanted again.

是否有任何方法可以防止FileUpload控件在回发期间丢失其内容?

Is there anyway to prevent the FileUpload control from losing its contents during the PostBack?

推荐答案

由于您尝试了Relster的建议,但该建议无效,因此Spencer是正确的.出于安全考虑,除了浏览器外,其他任何东西都无法在< input type ="file"/>中设置路径.元素.唯一的解决方案是重组流,以便在您要提交文件时进行唯一的回发,并使用客户端脚本进行其他任何处理.

Since you tried Relster's suggestion and it didn't work, Spencer is correct. Due to security concerns, it is impossible for anything but the browser to set the path in an <input type="file"/> element. The only solution is to restructure the flow so that the only postback is done when you want to submit the file, and do any other manipulation with client side scripting.

之所以无法设置路径,是因为它可以让您窃取用户的文件.例如,如果您隐藏输入,并有一个无害的回发按钮,则可以将文件输入的默认路径设置为想要访问的任何内容,而用户将不知道正在发生什么就上传它.

The reason you cannot set the path is because it would allow you to steal users' files. For example, if you hide the input, and have an innocent looking button for postback, you could set the default path of the file input to whatever you wanted to get access to, and the user would upload it without ever knowing what's going on.

这篇关于如何防止回发时清除FileUpload控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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