Thursday, January 31, 2008

FileUpload control in an UpdatePanel

By nature, FileUpload controls require an entire page postback to submit the file contents, so they are explicitly excluded from support within an UpdatePanel...however, if you put the Submit button that performs the postback intended to upload the file into a PostbackTrigger, you can place your FileUpload control within the UpdatePanel.


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

7 comments:

Venky said...

fgfg

Venky said...

Hai

File upload control in update panel the page is going to refresh while i am using Postback trigger with Control Id as Buttonn Id what should i do for eliminating this Page refresh

Venky said...

Any one suggest me

Steven Mc Donald said...

This doesn't work at all. Add an image above the update panel and you'll see that a postback still occurs

David Burton said...

Adding the control to the Triggers list ensures that a postback occurs - it just makes sure it's a full-page postback, not a partial page (asynchronous) update.
I had found I still had a problem having put this in, but it turned out that I was adding the FileUpload control onto the page in an asynchronous callback, which meant that the form type wasn't multi-part, and had to add code like the following to ensure that the file was included with the postback (in addition to the Triggers entry):

if (!IsPostBack)
{
this.Page.Form.Enctype = "multipart/form-data";
}

Unknown said...

thank you very much sir for your brilliant post

Chief Sahab said...

Thanks David .....its work