Ramani Sandeep's Blog

DotNetting – Fast , Easy Way of Developing Applications

File Upload Control is not working in Update Panel

Posted by Ramani Sandeep on November 22, 2008


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>

About these ads

8 Responses to “File Upload Control is not working in Update Panel”

  1. Adil said

    This is very helpful but when update panel is on master page this is not identified button id. so then what to do.
    Thanks

    • Ramani Sandeep said

      you can dynamically fetch the content page buttonid on master page load event & asssign the post back trigger Control Id.

      hope this idea will help you.

      • Shaker said

        I have a big issue with in the Asp.Net Update Panel i.e Update panel contains two File upload controls one is for Image updalod and second one is for Document uplload and with in this i have one Ajax model popup event for entering Address details into Grid. The issue is after upload an image/Document if i click on Model PopUp link it’s showing JavaScript error “Microsoft JScript runtime error: ‘myScriptpagename’ is undefined”. Can any one please explan how to implement two FileUploads and Ajax model popups in a sing update panel or multiple?

  2. Adil said

    Pleasesent me soloution by e mail.
    adilkhnajee@hotmail.com

  3. shri said

    he its working.Thanks

  4. When I use Validation for other controls, fileupload has been disabled. how to solve?

  5. Naresh said

    I have same problem..When I use other controls with validation fileupload is disabled…………

  6. swanand said

    thx it working very good

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 )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 124 other followers

%d bloggers like this: