FileUpload
FileUpload requires full page request. This is a limitation of the XmlHttpRequest component used in all AJAX frameworks for asynchronous calls to the application.
What really throws me is that I have this working in another project
(scriptmanager in masterpage, Fileupload in updatepanel, SaveButton is
PostbackTrigger).
I think you are using Full PostBack, although FileUpload is inside **UpdatePanel.
For example,
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="SaveButton" runat="server" OnClick="SaveButton_Click"
Text="Upload your file" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="SaveButton" />
</Triggers>
</asp:UpdatePanel>
AsyncFileUpload
If you use AsyncFileUpload with UpdatePanel, AsyncFileUpload.HasFile should only checked inside UploadedComplete (you cannot check inside Button click event).
The reason is AsyncFileUpload is uploaded the file via Async by itself.
Note: make sure you use ToolkitScriptManager instead of ScriptManager
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="Server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<ajaxToolkit:AsyncFileUpload runat="server" ID="AsyncFileUpload1"
OnUploadedComplete="AsyncFileUpload1_UploadedComplete" />
<asp:TextBox runat="server" ID="TextBox1" /><br/>
<asp:Button ID="SaveButton" runat="server" OnClick="SaveButton_Click"
Text="Save" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="SaveButton" />
</Triggers>
</asp:UpdatePanel>
private string FileName
{
get { return (string)(Session["FileName"] ?? ""); }
set { Session["FileName"] = value; }
}
protected void SaveButton_Click(object sender, EventArgs e)
{
string fileName = FileName;
string path = Server.MapPath("~/App_Data/");
var fileInfo = new FileInfo(path + FileName);
}
protected void AsyncFileUpload1_UploadedComplete(object sender,
AsyncFileUploadEventArgs e)
{
if (AsyncFileUpload1.HasFile)
{
FileName = AsyncFileUpload1.FileName;
string path = Server.MapPath("~/App_Data/");
AsyncFileUpload1.SaveAs(path + AsyncFileUpload1.FileName);
}
}
Other Thoughts
I personally do not like using AsyncFileUpload inside UpdatePanel. Instead, I'll rather use Full PostBack if I need to upload a file.