<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 是这样的:
function clickTheButton() {
document.getElementById('<%= Button1.ClientID %>').click();
}
问题很简单。 FileUpload1.HasFile == 假。我不知道这是为什么,但是当我将它放入更新面板时它就停止工作了。
我已经看到了一些其他线程。但是他们都没有回答为什么会这样,他们只是指出您可以下载的东西。
编辑:我想这样做的主要原因是我可以得到一个..Uploading File..标签在客户端上传到服务器时弹出,一旦完成,显示它在数据列表中。我只是无法让 UpdateProgress 工作。
最佳答案
基本上你只需要让你的按钮做一个完整的回发来发送文件。还要确保你有 this.Form.Enctype = "multipart/form-data";在您的代码中设置,或者您可以放入该页面。如前所述,出于安全原因,AsyncPostbacks 不适用于文件,没有黑客。 (我从来没能让它发挥作用)。
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload onchange="clickTheButton();" ID="FileUpload1" runat="server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Button1" />
</Triggers>
</asp:UpdatePanel>
关于c# - 嵌套在 UpdatePanel 中时 FileUpload 不起作用? C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2107952/