How to Preserve Fileupload value in ?

If you form has asp:Fileupload control along with other controls like dropdownlist, calendar.. you will be facing standard problem of Fileupload control losing (the file) value when users click upload first and dropdown next.

This problem can be solved by using Updatepanel.  (AJAX)

Place all the controls inside updatepanel and place the FileUpload control and Upload button outside the panel.

Any autopostbacks will be handled by AJAX and Full postback will be handled by Upload button. 


<asp:UpdatePanel ID=”UpdatePanel1″ runat=”server”>
      <asp:DropDownList runat=”server” ID=”ddl” AutoPostBack=”true”>  </asp:DropDownList>
      <asp:Calendar ID=”calAsOfDate” runat=”server” DayNameFormat=”Shortest”> </asp:Calendar>

Fileupload placed outside the Panel

<asp:FileUpload Width=”600″ ID=”uldReport” runat=”server” /> <br/><br/>

<asp:button ID=”cmdCancel” runat=”server” UseSubmitBehavior=”false” CausesValidation=”false” Text=”Cancel” />&nbsp;&nbsp;

<asp:Button ID=”cmdUpload” runat=”server” Text=”Upload” OnClick=”cmdUpload_Click” />

Problem solved !!

5 thoughts on “How to Preserve Fileupload value in ?

  • August 26, 2008 at 3:48 am

    But my layout is different. I have a Fileupload control in a Formview and for the whole container i put a single update panel. So i cant remove the file upload control from update panel. So wat to do with this prob?
    Is there any way to prevent the file upload control to donot participate partial page rendering? I mean inside update panel..

    Thanks in advance
    Murali M
    .Net developer

  • October 15, 2008 at 10:55 am

    This solved my problem. I separated the control out of update panel and that fixed it.

  • October 5, 2009 at 11:36 pm

    ur code only reserves the value but not the actual content! try to add selectedindexchanged event on ddl and do uldReport.FileName. You will get empty string!

  • January 5, 2012 at 3:17 pm

    thank you mannnnnnnnnnn, I was trying to find a solution for this for a long time.. The mistake I made was placing the update panel into whole page.. thanks..


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: