File upload control in UpdatePanel

I was running into an issue when I put File Upload control in Update Panel to use nice feature of AJAX. When It was doing postback everytime I was getting PostedFile property of FileUpload control to NULL. I was wondering why that was happening because that page was very simple not any complex code I wrote in there.

But there is a known issue that FileUpload control doesn’t work inside AJAX update panel. As always there should be some workaround for that. You need to do full page post back in order to upload file. We can’t use AJAX postback to upload file.

You can do full page post back using one of following solution.

1) You can add postbacktrigger for the button that causes a post back to upload file.

<asp:updatepanel runat=”server” id=”UpdatePanel1″>
<contenttemplate>
<asp:FileUpload runat=”server” id=”FileUpload” />
<asp:button runat=”server” id=”Upload” text=”Postback” />
contenttemplate>
<triggers>
<asp:postbacktrigger controlid=”Upload” />
triggers>

2) Another way to cause full page post back in code behind.

ScriptManager.GetCurrent(Page).RegisterPostBackControl(Upload);

Updated: 3) if you are using .NET 3.5 or higher version, you can use latest version of AJAX Control Toolkit that has a AsyncFileUpload control that works perfectly fine.

Hope this helps you!!!

Posted in Microsoft Technology Tagged with:
3 comments on “File upload control in UpdatePanel
  1. Elfmom says:

    Thanks for this, I love random information.

  2. Aurelio says:

    That helped a lot. Thanks!

  3. Shailesh says:

    @Aurelio, If you are using AjaxControlToolkit 3.0 or later version, you may find Async File upload control that work’s great with out any problem.

2 Pings/Trackbacks for "File upload control in UpdatePanel"
  1. File upload control in UpdatePanel | Broken Code…

    […]You need to do full page post back in order to upload file. We can’t use AJAX postback to upload file. You can do full page post back using one of following solution. 1) You can add postbacktrigger for the button that causes a post back … Howto…

Ads