文件上传时不起作用嵌套的UpdatePanel? C# [英] FileUpload Doesn't Work When Nested In UpdatePanel? C#

查看:172
本文介绍了文件上传时不起作用嵌套的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.

编辑:真是我的主要原因,想做到这一点,这样我可以得到一个..Uploading文件..标签弹出,而客户端上传到服务器,一旦完成,显示它在数据列表。我只是不能得到的UpdateProgress工作。

推荐答案

基本上你只需要让你的按钮做了充分的回传发送文件。另外,还要确保你有this.Form.Enctype =的multipart / form-data的;在code设置,或者你可以把该页面。 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>

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

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