Last post Feb 04, 2019 01:57 AM by Nan Yu
Feb 01, 2019 11:50 AM|anp123|LINK
I have an ASPX form with 2 Divs , First one for data entry text boxes and second Div for displaying submitted data in labels for preview. Both div are under one form
<form id="form1" method="post" enctype="multipart/form-data" runat="server"> .
When page is displayed, data entry div is displayed with entry text boxes along with asp:FileUpload Control. When the user submits the form, another div with labels with submitted information is displayed for user review and data entry div will be hidden.
There are 2 buttons in the user review div. One is back button and other is for final submission. When the Final Submission is done, asp:FileUpload Control "HasFile" property is showing null in spite of selecting the file , when data entry is done. How do
I retain the File in asp:FileUpload Control when the Final Submission button (In Preview DIV) is pressed, because in the on_click event of this button, the file is to be uploaded.
Feb 01, 2019 12:40 PM|PatriceSc|LINK
Not 100% clear but it seems you show again this web form when clicking on the first button. As this is a full postback the FileUpload control is cleared. You can't retain an existing value as for safety reason only the user can interactively populate this
A quick fix could be to add the FileUpload control to the fields shown before the final submit so that the user can only select the file as part of the 2nd step (even if it worked the file would be have been uploaded twice anyway). Or just get the file in
step 1 and show something telling the file was uploaded in step 2.
Other options are to use Ajax or as in web mails to handle this file upload as a separate step.
Feb 04, 2019 01:57 AM|Nan Yu|LINK
Generally, you aren't going to be able to persist a File through a PostBack (for security purposes), but if your entire page doesn't necessarily need to be posted back ( only the first submit in data entry div ,file is not need to send on first submit
) you can place your data entry div inside of an ASP.NET AJAX UpdatePanel, and keep your file upload control out of that.
Your update panel will do the post backs and allow your validation logic to happen without submitting the file, then when you hit your final "Final Submission" button (which is also outside of your UpdatePanel) the entire form will be submitted
back and you can work with your file then.
Best Regards ,