当fileupload控件在updatepanel下时如何上传图片?

发布于 2024-08-08 11:44:16 字数 180 浏览 3 评论 0原文

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 技术交流群。

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

发布评论

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

评论(4

≈。彩虹 2024-08-15 11:44:16

这是不可能的。出于安全原因,浏览器不允许 javascript 上传文件。

对于此问题,有两种正常的解决方法:

  • 在 iF​​rame 中执行上传
  • 使用 flash 插件进行上传

我最近应用此工具在我的网页中异步上传文件,效果非常好: 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:

  • Perform the upload in an iFrame
  • Use a flash plugin for uploading

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.

灰色世界里的红玫瑰 2024-08-15 11:44:16

我曾尝试如下。它正在发挥作用。

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Upload" runat="server" Text="Upload" OnClick="Upload_Click" /><br />
<asp:Image ID="NormalImage" runat="server" /></ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Upload" />
</Triggers>
</asp:UpdatePanel>

参考

http: //www.c-sharpcorner.com/uploadfile/prathore/fileupload-control-in-update-panel-using-Asp-Net-ajax/

I had tried as below. It is working.

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Upload" runat="server" Text="Upload" OnClick="Upload_Click" /><br />
<asp:Image ID="NormalImage" runat="server" /></ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Upload" />
</Triggers>
</asp:UpdatePanel>

Reference to

http://www.c-sharpcorner.com/uploadfile/prathore/fileupload-control-in-update-panel-using-Asp-Net-ajax/

薄情伤 2024-08-15 11:44:16

你可以试试这个代码。我试过了,它对我有用。

<asp:ScriptManager runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<div>
<asp:FileUpload ID="FileUpload1" runat="server" /> <br/>
<asp:Button ID="btn_Upload" runat="server" Text="Save" OnClick="btn_Upload_Click" /><br />
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btn_Upload" />
</Triggers>
</asp:UpdatePanel>

You can try this code. I tried it, it's working on my side.

<asp:ScriptManager runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<div>
<asp:FileUpload ID="FileUpload1" runat="server" /> <br/>
<asp:Button ID="btn_Upload" runat="server" Text="Save" OnClick="btn_Upload_Click" /><br />
</div>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btn_Upload" />
</Triggers>
</asp:UpdatePanel>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文