4
Digg me

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. 

Example:

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

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 !!

If you enjoyed this post, make sure you subscribe to my RSS feed!


5 Comments to “How to Preserve Fileupload value in Asp.net ?”

  1. How to Preserve Fileupload value in Asp.net ? « Script(s) | May 1st, 2008 at 7:41 pm

    [...] Click here to read the article in full… [...]

  2. Murali | August 26th, 2008 at 3:48 am

    Hi
    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

  3. gchandra | August 29th, 2008 at 11:32 am

    Murali

    Try this technique, might work for your case.

    http://geekswithblogs.net/ranganh/archive/2007/05/16/112524.aspx

    Let me know if it helps :)

  4. Santhosh | October 15th, 2008 at 10:55 am

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

  5. Ron | October 5th, 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!

Leave a Comment