How to use FileUpload control inside ASP.Net AJAX Update Panel

There are plenty of questions asked by developers around the globe that they are not able to use FileUpload asp.net control inside ASP.Net Ajax update panel. Their issues are FileUpload control inside Asp.Net Ajax update panel doesn’t hold any file and also return false for HasFile property whenever they upload any file.

Don’t worry! This is because the uploading and manipulations of files are restricted by default in client side for security purpose. That’s why this is not possible to upload files using asynchronous postback in UpdatePanel. you can do it just by changing the Trigger of the upload button from AsyncPostBackTrigger to PostBackTrigger.

Note – Asp.Net Controls that are reside in updatepanel, cause an async postback/update by default. That’s why the page will postback and get partial rendering. Now if for any reason you have control inside an updatepanel which you have to make a full postback rendering, then you need to set it explicitly as a postbacktrigger.

ASP.Net Webform(Aspx) Code :

To use ASP.Net Ajax, you have to add reference ajaxcontroltoolkit.dll in your solution first then you can use below code to upload a file.

Code behind .cs code :

For demo purpose, I am trying to allow the user to upload only jpg or jpeg images.

 

About Ravi Ranjan Kumar 32 Articles
An Indian who Living, Loving & Learning Technology with different tastes and willing to share knowledge and thoughts.

Be the first to comment

Leave a Reply