How can I change text and other properties of the label control after a file uploads.
File uploading updating client side jQuery widget from server side event. In ASP.NET the server respond to client request. To return request the framework constructs response as executes page cycle– calling events like prerender, render, load, etc. However, WebUpload server side events for starting and finishing upload are called asynchronous – after the server has returned response then it is fired events – file starting, uploading, and uploaded. These events are fired from HttpModule – and that’s why when these events are fired then the normal page life cycle is not executed. Since the page does not go to its full life cycle it is not possible to change values on server side. For instance – you have one page with WebUpload in it. You have attached to server side events for starting file and for finishing. When the client requests the page then the server respond as executing the whole page life cycle and returns page with Webupload in it. During this page life cycle then it is called page prerendered, page rendered, page load, etc. The response is sent to client and page life cycle ends. Then the user selects file and click upload button. Then asynchronously the server side event of WebUpload for starting upload is called. This event is fired NOT as a result from “normal” page request – it is not postback. This event is fired from HttpModule and that’s why the whole page life cycle is not executed – page is not pre rendered, nor rendered. Since the page does not go through whole life cycle it is not possible to change values of other controls on the page.
If you want to implement the mentioned functionality you should attach to UploadFinished event in client side (not from the server side event). Also if you want to get some information from the server – for instance some info about uploaded file – he could make AJAX request to get it from the server. However, all of these should be made on client side, because these server events are called ASYNC and page is NOT refreshed. And that’s why even if you change file upload control from the event handlers in code behind changes will not be applied.
The below line of code will give more details on this:
function WebUpload2_FileUploaded(eventArgs, infoObject){ // Get the Label control and change its text. $("#lbl1").text(infoObject.totalSize + "" + infoObject.filePath);}
I hope this helps.