The FileUpload control will not work inside an UpdatePanel control for uploading files using Asynchronous postback. This is because file uploading and file manipulations are restricted by default in the client side for security reasons. Hence it is not possible to upload files using asynchronous postback in UpdatePanel.
File upload controls do not work in AJAX update panels and the upload control needs to do full page postback. This means that if your upload control is located in an update panel, then the control does not post the file. If you look to the posted file property of the control, you will see it is null. So, the control always has to post full page postback.
To resolve this problem we need to rely upon a standard postback i.e. we need to set the button that is uploading the file to be PostBack trigger instead of AsyncPostBack trigger. This will initiate a normal postback whenever we click the upload button and then it is possible to upload the file.
You need to create a PostBackTrigger for the button that initiates postback like as follows.
<Triggers>
<asp:PostBackTrigger ControlID="Upload" />
</Triggers>
For Example:
InLine Code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<table width="50%" cellpadding="2" cellspacing="0">
<tr>
<td>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Upload" runat="server" Text="Upload" OnClick="Upload_Click" /><br />
<asp:Image ID="NormalImage" runat="server" /></ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Upload" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
CodeBehind code:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Upload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(MapPath("~/Image/" + FileUpload1.FileName));
System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("~/image/") + FileUpload1.FileName);
NormalImage.ImageUrl = "~/Image/" + FileUpload1.FileName;
}
}
}
Output: 

mayur savaliyaPosted Aug 3, 2015, 3:51 AM
i want 10 file upload control in one page but it is not possible in asp.net why it occur error please give me reply any one know
hothorasman panjaitanPosted Jan 28, 2015, 12:55 PM
hi all master asp.net help me how to use three fileupload in asp.net database mysql
Akhil MittalPosted Apr 12, 2014, 8:07 AM
On Refreshing the page after upload, File Upload should be empty, but it shows that it contains file.and also it jumps to upload_click event even if it is not clicked.??????????
angel adinolffiPosted Jan 27, 2014, 4:42 PM
In this article an example of how to solve the problem: http://www.systemdeveloper.info/2014/01/fileupload-control-in-update-panel.html
Smart LuckyPosted May 30, 2013, 9:46 AM
Nice Article
Saurabh KudaleeditedPosted Apr 26, 2013, 1:59 AMEdited Apr 26, 2013, 2:00 AM
mitra refresh hotay page..I mean mitra page is reloading..
imran_zetaPosted Apr 14, 2013, 2:03 AM
nice article
imran_zetaPosted Apr 14, 2013, 2:03 AM
nice article
Govinda GhimirePosted Mar 31, 2013, 2:46 AM
ok
Former memberPosted Sep 30, 2012, 1:21 PM
This is really nice article http://www.dotnetpools.com/Article/ArticleDetiail/?articleId=5&title=Fileupload%20Control%20In%20Asp.net
Dadu DaPosted Jul 25, 2012, 2:34 AM
It is not working dear I try as you mentioned I am unable to get the file on click event the file name always blank and the FileUpload1.HasFile always false
hello kittyPosted Apr 9, 2012, 6:41 PM
Hi Purushottam, First thanks for sharing your code. It doens't seem work for me. I got error: The type or namespace name 'UpdatePanel' does not exist in the namespace 'System.Web.UI.WebControls.WebParts' (are you missing an assembly reference?) Any suggestion on that? Thanks in advanced.
ABEJIDE ADEIBIJOLAPosted Jan 19, 2012, 3:33 AM
I spent almost a day looking for the bug that never existed until I saw this site! This article was VERY helpful. Thank you Rathore!
Shreeharsha BRPosted Jan 3, 2012, 12:51 PM
Thank you Mr. Purushottam Rathore for sharing the knowledge. It is what exactly i need.
Rajkumar BPosted Dec 20, 2011, 2:23 AM
Its working fine. I need get the FileUpload control on client side and which is available on Update panel. Please clarify me.
rafat snowPosted Sep 14, 2011, 5:09 AM
i need you help to help me for send e_mail code using asp.net(vb) on vs 2008> and it is working without publich it(website) than's
jaimin bhagatPosted Aug 4, 2011, 2:00 AM
when i added update progress for update panel the image is not shown on screen. can you please help me.
MASUDUL HAQUEPosted Jul 10, 2011, 7:44 AM
Yes your process is fine but i want to use that image as a profile in forum project how do that
narikg8373editedPosted Apr 21, 2011, 7:37 AMEdited Apr 21, 2011, 7:39 AM
when i use the code below, it's working fine but with page postback. <Triggers> <asp:PostBackTrigger ControlID="Upload" /> </Triggers> And if I use the following code, i am getting null value in FileUpload1.PostedFile.FileName. <asp:AsyncPostBackTrigger ControlID="btnUpload" EventName="Click"></asp:AsyncPostBackTrigger> Please let me know how I can manage this. Thanks in advance Kiran.
aini eiyaPosted Apr 12, 2011, 3:57 AM
can i know how to save file upload in asp.net to mysql?
vamsi krishnaPosted Jan 31, 2011, 12:09 PM
im using update panel in master page so how can i specifies upload button id inside <Triggers></Triggers> .
Jitendra ChilatePosted Jul 24, 2010, 6:09 AM
its good purushottam , i have implemented it on my page.
Varun SoodPosted Jun 2, 2010, 3:11 PM
Thanks a lot dude....keep up the good work...
jasmin shikalgarPosted Aug 17, 2009, 3:35 AM
Thanks a lot, exactly what I needed!!