I have an .aspx page with a WebDataTree control, a WebHierarchicalDataSource control (configured with 2 SqlDataSource controls), and a WebUpload control.
It's a simple setup, user uploads a file, which executes some code-behind that updates the database, which should then refresh the WebDataTree. The tree is indeed initially populated with existing data. And Uploading new files should refresh that list.
The database does get updated with new file information, and If I force a page refresh the tree does get repopulated. But I'd like the WebDataTree to repopulate once a file is uploaded, which I normally do by calling the control's DataBind() on post back, in this case WedDataTree1.DataBind() during the WebUpload1_UploadFinished() event.
But this does not refresh the WebDataTree control. Am I missing something? Is this not the way to refresh the control?
Thanks for getting back to me.
I've since learned more about the control and opted for placing the webdatatree inside an update panel and making a call to __doPostBack('UpdatePanel1','') inside the WebUpload1_FileUploaded client event.
Thanks for your time
Hi Dave Festa,
Most of the extra javascript code in my sample is used to check if all files have finished uploading. If you have the WebUpload available for only one file, you can handle only the FileUploaded client event and trigger the button click for a postback.
The issue in this scenario is that when the WebUpload uploads a file, the request is not made to the aspx page and the response is not sent back as HTML. If you check your network traffic, the response consists of "<root></root>" and the page is not updated. Any code that runs on the page will still have an effect, such as updating the database or binding the WebDataTree, but since there is no HTML or Ajax response, the page isn't updated. With my sample, you can remove the UpdatePanel and see how the page does a full postback and updates.
This is why it is necessary to detect when the files are uploaded on the client, so the request can be made to the page which will respond with an HTML page (or Ajax update).
If you have any further questions or concerns with this, please let me know.
Thank you for the reply.
After looking over your sample code it seems your introducing an awful lot of extra code just to generate a Postback (or partial postback in your example) when the WebUpload control already does this, I can debug and break on this server side event:
WebUpload1_UploadFinished(sender As Object, e As UploadFinishedEventArgs) Handles WebUpload1.UploadFinished
It's at this point I save the file to my database (which succeeds) and attempt to refresh the WebDataTree via DataBind() during a full postback.
Why do I need to create and then hook into the client side WebUpload1_FileUploaded event to fire a click event of an invisible button inside an update panel(which doesn't exist in my example) to generate a partial postback to update the tree/label. Why is the server side event not enough?
Thank you for posting in our forums!
The reason the WebDataTree is not refreshing is due to the WebUpload sending requests to the WebUpload's handler rather than to the page. The browser is not expecting a response from the page, and does not update anything. If you check your network traffic, you will see this.
To update the page, you will need to determine on the client side when the uploads are finished and make a request to the page to see any new data. I have attached a sample that demonstrates how this can be done. Once the files are uploaded, the client triggers a postback that updates the label.
To run this sample, you will need to import your ig_ui folder into the project. This can easily be done by opening the design surface in Visual Studio. The designer will prompt you to import the folder automatically.
If you have any further questions or concerns with this, please let me know and I will be glad to help.