1. After using UpdatePanel, HasFile of FileUpload is always false, no matter whether you have selected upload file or not!
Option 1: Set EnablePartialRendering="false" of ScriptManager! Disadvantage: Multiple UpdatePanels on the same page cannot be refreshed independently. In addition, when there is a Validator (validation control) in your UpdatePanel, it will cause the entire page to postback
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="false"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:FileUpload ID="fu" runat="server" /> </ContentTemplate> </asp:UpdatePanel>
Option 2: Source: http://marss.co.ua/FileUploadAndUpdatePanel.aspx
PostBackTrigger indicates the button ID submitted by PostBack, and there is also an <asp:AsyncPostBackTrigger /> which is of course asynchronous! PostBackTrigger He only sends back the contents of the UpdatePanel and will not affect the postbacks of other UpdatePanels
Using the PostBackTrigger control enables controls inside the UpdatePanel to cause a postback instead of performing an asynchronous postback.
For details on using FileUpload in UpdatePanel, see: http://msdn.microsoft.com/zh-cn/library/system.web.ui.postbacktrigger.aspx
<form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel runat="server" ID="up1"> <ContentTemplate> <asp:FileUpload ID="fu" runat="server" /> <asp:Button ID="BtnUpload" runat="server" Text="Upload" onclick="Btn_Click" /> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="BtnUpload" /> </Triggers> </asp:UpdatePanel> </form>