This is an inherited button control which can perform file upload like in gmail manner. The button uses the inherited
IFRAME technique to avoid full page rendering so that user will get a nice experience.
IFRAME technique. Here I have created an derived ASP.NET Button control which can perform the trick.
Using the code
To open the project, unzip it and open the file FileUploadControlTest.sln Open the file UploadButton.cs. The
OnInit method will register the
onsubmit statement to client.
onsubmit script creates a new hidden
IFRAME in the dom and sets the
target of the form to this
IFRAME. So the section the user is seeing will not get redrawn after postback. In the
Page_LoadComplete event of the page, we will get the FileUpload control filled with the uploaded file. We will call the event handler in the
Page_LoadComplete method. The return text after executing the event handler will be returned to the client.
onload method of
IFRAME, we will call the function registered as
OnCompleteScript, and pass the text inside the
IFRAME which is the response text.
Points of Interest
The hidden IFRAME technique is an old one but in some complex situations, it will help us !!!