Home > AJAX, ASP.Net > File Upload Control is not working in Update Panel

File Upload Control is not working in Update Panel


The essence of the problem is that the FileUpload control does not work with asynchronous postbacks, and therefore does not work from within an AJAX UpdatePanel.

The technique presented in this article allows the FileUpload control to work within an UpdatePanel, by forcing a full postback; however, the rest of the controls can still take advantage of the asynchronous postbacks provided by the UpdatePanel.

Solution
——–

The trick is to force the file upload control to perform a full postback, and we do this using triggers. Triggers allow the developer to specify what will cause partial and full postbacks. They must be defined within the UpdatePanel but outside of the ContentTemplate. We want to create a trigger that will instruct the button that we are using for the upload to perform a full postback.

<asp:UpdatePanel ID=”UpdatePanel1″ runat=”server” UpdateMode=”conditional”>
<Triggers>
<asp: PostBackTrigger ControlID=”Button1″ />
</Triggers>
<ContentTemplate>

<asp:FileUpload ID=”FileUpload1″ runat=”server” />
<asp:Button ID=”Button1″ runat=”server” Text=”Upload” OnClick=”Button1_Click” />

</ContentTemplate>
</asp:UpdatePanel>

Good Luck

Advertisements
Categories: AJAX, ASP.Net Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: