I'm creating a page that users can upload a file to the webserver. After upload the page will then have a link to the file that has just been uploaded, along with any other files that have already been uploaded.
As I am programatcially creating links to the files which have been uploaded, I have to do this in page_init or else the link button won't fire off it's event when clicked. MY web page does all this - it creates the link buttons and when I click on them, it calls the event method requi开发者_如何学JAVAred i.e. a sub to download the file.
OK, the problem I've come accross is: when I click upload (to upload the file) - the page_init sub is called, displaying all the previously uploaded files as link buttons. Then my btnUpload_click sub is called, which uploads my current file.
The only prob is the current file hasn't been displayed? I can only display links in the page_init, but because btnUpload is called after the page_init, the current file isn't uploaded until after page_init and therefore not dislayed?
Any ideas how to get around this?
Have list of all the server side links as member of your class:
List<LinkButton> myLinks = new List<LinkButton>();
When you build the links don't add them to the page yet, add them to the List instead:
myLinks.Add(oNewLink);
In the btnUpload_Click method, add new link to the global list with the proper values.
Add the links to the page in the Page_PreRender function, which happens after the button click.
If you need further help implementing this logic let me know. :)
if you are getting/saving the list of previously uploaded files from Session variable or Database, then at the end of btnUpload_click event, you can simply redirect the page to itself. Like Response.Redirect("PageName.aspx");
精彩评论