FileUpload 嵌套在 UpdatePanel 中时不起作用?C# [英] FileUpload Doesn't Work When Nested In UpdatePanel? C#

查看:17
本文介绍了FileUpload 嵌套在 UpdatePanel 中时不起作用?C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                        <asp:FileUpload onchange="clickTheButton();" ID="FileUpload1" runat="server" />
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="Button1" />
                </Triggers>
</asp:UpdatePanel>

按钮 1 在更新面板之外,当用户在上传框中添加文件时运行的 javascript 是这样的:

Button 1 is outside the update panel and the javascript that gets run when a user adds a file in the upload box is this:

function clickTheButton() {
            document.getElementById('<%= Button1.ClientID %>').click();
        }

问题很简单.FileUpload1.HasFile == 假.我不知道为什么会这样,但是当我将它放入更新面板时,它就停止工作了.

我看过其他一些关于此的主题.但是他们都没有回答为什么会发生这种情况,他们只是指出您可以下载的内容.

I have seen some other threads on this. But none of them answer why this is happening, they just point to things you can download.

真的我想要这样做的主要原因是我可以得到一个..上传文件..标签在客户端上传到服务器时弹出,一旦完成,显示它在数据列表中.我只是无法让 UpdateProgress 工作.

推荐答案

基本上你只需要让你的按钮做一个完整的回发来发送文件.还要确保你有 this.Form.Enctype = "multipart/form-data";在您的代码中设置,或者您可以放入该页面.出于安全原因,AsyncPostbacks 不适用于文件,没有黑客攻击.(我一直无法让它工作).

Basically you just need to make your button do a full postback to send the file. Also make sure that you have this.Form.Enctype = "multipart/form-data"; set in your code, or you can put in that page. AsyncPostbacks don't work with files for security reasons as mentioned, without hacks. (I've never been able to get it to work).

 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
      <ContentTemplate>
           <asp:FileUpload onchange="clickTheButton();" ID="FileUpload1" runat="server" />
      </ContentTemplate>
      <Triggers>
         <asp:PostBackTrigger ControlID="Button1" />
      </Triggers>
 </asp:UpdatePanel>

这篇关于FileUpload 嵌套在 UpdatePanel 中时不起作用?C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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