user441521
user441521

Reputation: 6998

asp.net submit button inside update panel and fileupload controls

I have 3 file upload controls where people upload csv files. If my submit button isn't inside an update panel the file upload have the files in the code behind and everything works fine. However, I would like my submit button inside an update panel as based on some other controls on the form I enable/disable the button via the update panel. This enabling and disabling works fine, but now in the button click codebehind the file upload controls always have null values even though a csv file was selected.

Why is the update panel around my submit button causing the file upload controls to not have anything in them even though files were selected?

So I have a FileUpload control on the page like:

<asp:FileUpload ID="file1" runat="server" />

I have a submit button in an update panel like:

<asp:UpdatePanel ID="pnlSubmitButton" runat="server" UpdateMode="Conditional">
  <ContentTemplate>
      <asp:Button ID="button1" runat="server" Test="Submit" onclick="button1_Click" />
  </ContentTemplate>
</asp:UpdatePanel>

In my code behind on the button click event

protected void button1_Click(object sender, EventArgs e)
{
    // file1.FileName is empty even though I did select a file
}

If I remove the update panel around the button file1.FileName in the button click is then populated

Upvotes: 0

Views: 5558

Answers (1)

user240141
user240141

Reputation:

As far as I know, asp:FileUpload wont works under UpdatePanel async trigger. You need to set upload button click under post back trigger to make it working. Something like this:

<triggers>

<postbacktrigger controlid="btnSubmit"/>
</triggers>

Upvotes: 3

Related Questions