2

I have got multiple Update Panels(asp:UpdatePanel) and in each of those update panels data is inserted and shown in the corresponding grids(grids too include in update panels).
I have the problem that I have a asp:FileUpload Control which is reset when data is inserted in those update panels since few controls have AutoPostBack="true".
I have found one of the closer solution at:-
http://www.codeproject.com/Tips/101834/How-to-Maintain-FileUpload-Control-s-State-after-P

        if (Session["FileUpload1"] == null && theFile.HasFile)
        {
            Session["FileUpload1"] = theFile;
            lblStatus.Text = theFile.FileName;
        }
        else if (Session["FileUpload1"] != null && (!theFile.HasFile))
        {
            theFile = (FileUpload)Session["FileUpload1"];
            lblStatus.Text = theFile.FileName;
        }
        else if (theFile.HasFile)
        {
            Session["FileUpload1"] = theFile;
            lblStatus.Text = theFile.FileName;
        }


But this solution is not resolving my problem. Unfortunately all these three if-else checks are not passing the condition.
I guess that there is some issue related to the UpdatePanel used in parallel with FileUpload control.
I have searched a lot of articles, but it could not find the resolution. Kindly help me in this regards at earliest.

Muzaffar Ali Rana
  • 487
  • 4
  • 11
  • 22

2 Answers2

0

I had same problem and resolved by adding below line in page load event:

Page.Form.Attributes.Add("enctype", "multipart/form-data");
Jitendra G2
  • 1,196
  • 7
  • 14
0

You are right! FileUpLoad does not work in UpdatePanel. You must force full postback to make it works. you have to add an asp button in the updatePanel to save the selected file. in the click event save the fileName in the session.. but also to force full post back you have to add trigger to the UpdatePanel. the UpdatePanel should look like this:

     <asp:UpdatePanel ID="UpdatePanel4" runat="server">
        <ContentTemplate>
            <asp:FileUpload ID="FileUpload1" runat="server"/>
            <asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="Button" />
        </ContentTemplate>
        <Triggers>
            <asp:PostBackTrigger  ControlID="Button3" />
        </Triggers>
    </asp:UpdatePanel>

for more info you can read in the following URL: http://www.codeproject.com/Articles/16945/Simple-AJAX-File-Upload

Hope it was helpful...

st mnmn
  • 3,555
  • 3
  • 25
  • 32