当fileupload控件在updatepanel下时如何上传图片?
updatepanel下fileupload时如何上传图片?
我在更新面板中有一个“上传”按钮。
当我单击按钮单击事件中的该按钮时,我得到 fileupload hasfile=false。 请建议当文件上传控件位于更新面板内并且按钮正在进行异步回发时,是否有任何方法可以上传图像文件。
提前致谢。
How to upload an image when fileupload is under updatepanel?
I have a button say "upload" inside that update panel.
When I click that button inside the button click event I got the fileupload hasfile=false.
Please suggest if there is any way to upload image file when fileupload control is inside update panel and the button is making asyncpostback.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用AJAX AsyncFileUpload控件
http://www.asp.net/ AJAX/AjaxControlToolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx
另请检查此线程。
在 AJAX updatepanel 中上传文件,无需完整回发
you can use AJAX AsyncFileUpload control
http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AsyncFileUpload/AsyncFileUpload.aspx
Also check this thread.
File uploading in AJAX updatepanel without full postback
这是不可能的。出于安全原因,浏览器不允许 javascript 上传文件。
对于此问题,有两种正常的解决方法:
我最近应用此工具在我的网页中异步上传文件,效果非常好: http://valums.com/ajax-upload/
它会自动为您创建一个 iFrame,发布该框架并将生成的 html(或 json 对象)发送到事件处理程序。我的页面接收上传的文件,返回一个描述文件的 json 对象,例如文件名和唯一的 id,以便我可以将主页上发布的数据链接到上传的文件。
为了安全起见,我存储上传文件的用户的凭据,因此当发布表单时,我可以验证发布表单的用户确实是上传文件的用户。
It is not possible. For security reasons, the browser does not allow javascript to upload files.
There are two normal workarounds for this problem:
I recently applied this tool to upload files asynchronously in my web page, and it works beatifully: http://valums.com/ajax-upload/
It creates an iFrame for you automatically, and posts the frame and and sends the resulting html (or json object) to an event handler. My page that receives the uploaded file, returns a json object describing the file, e.g. filename and a unique id, so that I can link the data that is posted on the main page to the uploaded file.
For security, I store the credentials of the user uploading the file, so when the form is posted I can validate that the user that posts the form is indeed the user that uploaded the file.
我曾尝试如下。它正在发挥作用。
参考
http: //www.c-sharpcorner.com/uploadfile/prathore/fileupload-control-in-update-panel-using-Asp-Net-ajax/
I had tried as below. It is working.
Reference to
http://www.c-sharpcorner.com/uploadfile/prathore/fileupload-control-in-update-panel-using-Asp-Net-ajax/
你可以试试这个代码。我试过了,它对我有用。
You can try this code. I tried it, it's working on my side.