File upload with ASP.NET AJAX UpdatePanel

I’ve been working with the Microsoft AJAX toolkit recently (and not so much Windows Mobile – hence lack of update :) . It’s an amazing framework for people who don’t know much JavaScript but still would like to do some AJAX style web programming (like me). However since it involves a combination of .NET server side programming, HTML and client side JavaScript figuring out what’s wrong when something doesn’t work can be tricky. I’ll try to post a few tricks I found (mostly on ajax.asp.net  :) even though it’s not directly related to mobile programming.

The ASP.NET FileUpload control doesn’t work within an AJAX UpdatePanel by default (when the upload button you create is inside the same panel). This is because a file cannot be uploaded asynchronously. To be able to upload a file the easiest solution is to make a complete postback when the user uploads a file. To do this add a PostBackTrigger on the button:

<asp:UpdatePanel>
  <ContentTemplate>
<asp:Button ID="ButtonUploadFile"
    runat="server" Text="Upload" />
</ContentTemplate>
  <Triggers>
<asp:PostBackTrigger ControlID="ButtonUploadFile" />
  </Triggers>
</asp:UpdatePanel>

(note that it is not an AsyncPostBackTrigger)

11 Responses to “File upload with ASP.NET AJAX UpdatePanel”

  1. vpanta Says:

    Hi,
    The first time, upload not function, why ?

  2. Ali Ahmad Says:

    Hi,

    Try this

    in place of

    Let me know if you further face some problem.

    Bye
    ALI

  3. Ali Ahmad Says:

    Hi,
    Try this

    in place of

    Previously I copied and paste but not shown in above, as you can see.
    Bye

  4. matt ridley Says:

    in response to vpanta, take a look at this, worked for me….
    http://marss.co.ua/FileUploadAndUpdatePanel.aspx

  5. Grozny Says:

    Somehow i missed the point. Probably lost in translation :) Anyway … nice blog to visit.

    cheers, Grozny.

  6. Anonymous Says:

    this is not working
    when we browse file
    after 20 second these are lost
    please send me solution.
    Thanks in advance

  7. hans Says:

    thanks for this post !

  8. $columns[1] Says:

    $columns[4]

  9. agsy Says:

    this is crap! It doesn’t work at all!!!

  10. Anonymous Says:

    FYI, someone is ripping off your post man:

    http://www.mehmetcatkin.com/post/2008/01/FileUpload-and-Ajax-UpdatePanel.aspx

  11. 1 Says:

    Bad.. this method isn’t the best form for get the solution to this problem… The best form, though it have more difficulty is use Iframes.

    http://forums.asp.net/p/1377113/2902896.aspx#2902896

Leave a Reply