Posted by Anuraj on Thursday, July 25, 2013 Reading time :1 minute
This is an old ASP.Net hack to upload file without page refresh in ASP.Net web pages.
You couldn’t upload a file without post back using normal file upload control. (Yes I agree with Ajax Toolkit or using HTML5 it is possible). To achieve the no refresh or no postback, we are placing the File upload control and upload button in a Web page (upload.aspx) and in the main page (default.aspx) we will be loading the File upload page in an IFRAME.
For displaying upload progress, a GIF image is used, the style of the image will be none by default. In the upload button onClientClick event, the display style will be changed to block.
Source code Here is the markup of Upload.aspx page.
And here is the code behind.
And here is the markup of default page.
There is no code in the code behind file of default.aspx.
As I mentioned in the top it is a hack, if you need a real solution, either you can use HTML5 File API and XHR or you can use AjaxToolkit Async File upload control.
What do you think? I would like to hear your thoughts, suggestions, and questions in the comments section below.