File Upload Control is not working in Update Panel


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>

Advertisements

8 thoughts on “File Upload Control is not working in Update Panel

    1. 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.

      1. 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?

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 )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s