locked
FileUpload control postback issue RRS feed

  • Question

  • User830892125 posted

    Hi,

    I have a FileUpload control <asp:FileUpload ID="Upload1" runat="server" />  along with other controls.

    I have a button(other than Submit) which causes a postback. The problem is that when a postback occurs, the selected path in the FileUpload control blanks out.

    Why does this happen with only FileUpload whereas all other controls retain there value. How do I prevent this from happening? I have EnableViewState=True on the FileUpload.

    Thanks

    Tuesday, September 4, 2007 7:42 AM

Answers

  • User998605613 posted

    I dont know why it does not retain the value during post back. It could be due to the security reason which they state in the uploadfile control reference in MSDN (

    For security reasons, you cannot pre-load the name of a file into the FileUpload control.) So when there is a postback I think it takes the existing file path as a preload and takes it off.

    I think from this it is evident that the file path is not retained when there is a post back.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 4, 2007 10:49 AM

All replies

  • User711226119 posted
    This is the property...You have to set it by hard codin as ISpostBack=False or true depending on your need. try to do by that. I think you will get back the correct result.
    Tuesday, September 4, 2007 8:46 AM
  • User1730632263 posted

    You cant set the Value to the File Upload control. So on the PostBack that File is Actually Uploaded to server ( which you might not handled in that button click).  

    Tuesday, September 4, 2007 8:51 AM
  • User830892125 posted

    Hi,

    The button is just for a popup to fill some values. The form(and the image too) gets submitted only when the Submit button is clicked and not on any other button.

    Can anyone else suggest me a way to handle this situation.

    Thanks

    Tuesday, September 4, 2007 9:10 AM
  • User998605613 posted

    How are you opening the pop up window?

    If you are using the RegisterStartupScript then it is going to definitely post back otherwise the pop up wont appear.

    I would suggest that you use Javascript to open the pop up and instead of ASP .Net web button control use HTML Button control.

    Hope this helps.

    Tuesday, September 4, 2007 9:19 AM
  • User830892125 posted

    Hi,

    Isn't there any other way? In the first place, why does the asp:FileUpload loose its value on postback?

    Thanks.

    Tuesday, September 4, 2007 10:06 AM
  • User998605613 posted

    I dont know why it does not retain the value during post back. It could be due to the security reason which they state in the uploadfile control reference in MSDN (

    For security reasons, you cannot pre-load the name of a file into the FileUpload control.) So when there is a postback I think it takes the existing file path as a preload and takes it off.

    I think from this it is evident that the file path is not retained when there is a post back.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 4, 2007 10:49 AM
  • User835306888 posted

    It is because their might be fileupload control inside the update panel

    Thursday, July 22, 2010 6:03 AM