Rahul Prajapat

Rahul Prajapat

  • NA
  • 1.6k
  • 635.2k

FileUpload control within UpdatePanel in asp.net

Jun 17 2015 10:30 PM
My source file is:
 
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" Text="Upload" onclick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel> 
 
and code behind code is:
 
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string Prefix = DateTime.Now.ToString("ddMMyyhhmmsstt");
string Doc_Name = (Path.GetFileName(FileUpload1.PostedFile.FileName)).Split('.')[0].ToString();
string str = FileUpload1.FileName;
string targetPath = Server.MapPath("~\\images\\Docs\\") + Prefix + FileUpload1.FileName;
FileUpload1.SaveAs(targetPath);
}
}
 
 My problem is that FileUpload1.HasFile return false, why ?
And how can fix it and save the file in folder.
Please help me...
Thanks in advance.

Answers (9)