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