KeyLimeTie Blog

Enable File Upload on an AJAX Webpage

By Brian Pautsch – 11/8/2007 9:51:35 PM. Posted to Code Snippets.

File uploads do not work when doing async postbacks due to security restrictions. Because of this, we have to add a PostBackTrigger. PostbackTriggers enable controls inside an UpdatePanel to cause a postback instead of performing an asynchronous postback. Here's a code snippet that shows how to accomplish this.
 
<asp:Content ID="Content1" ContentPlaceHolderID="cphContent" runat="Server">
    <asp:UpdatePanel ID="UpdatePanel1" runat ="server">
        <Triggers>
            <asp:PostBackTrigger ControlID="imgbtnUpload" />
        </Triggers>
         <ContentTemplate>
              <asp:FileUpload ID="txtFile" runat ="server" />
            <asp:ImageButton ID="imgbtnUpload" runat="server" ImageUrl="~/Common/Images/upload.gif" OnClick="imgbtnNext_Click" />
        </ContentTemplate>
    </ asp:UpdatePanel>
</ asp:Content>

By adding the PostbackTrigger, you can mix controls that make AJAX calls with controls that require the postback and maintain the good user experience.

Comments

Leave a Comment

Name:
Email:
URL:
Comment:
Security Code:
Type Security Code:

Photos on Flickr

More Photos »

Search Blog


Get Email Updates

Like what you read here at KeyLimeTie? Sign up for our email list!

Subscribe