Persist the value in file uploader in .net

How can the value of Fileuploader persisted on postback in .net
Who is Participating?
clinton_cunninghamConnect With a Mentor Commented:
use a hidden field, i've done this plenty for the exact same reason. I hate losing the selected file when my validation catches somthing on postback.

So basically, when a fileupload field is entered, or just before the postback event.
copy the file location into the hidden field. then read and populate the fileupload on IsPostback.

Here's some code:

             <asp:FileUpload ID="uploadHTMLHiddenField" runat="server"></asp:Label>
 .            <input id="HTMLHiddenField" type="hidden" name="HTMLHiddenField"/>
   protected void Page_Load(object sender, EventArgs e)
             // Insert message to the label of the html control hidden
             // field if there is a value in the html hidden field
             string message = Request.Form["HTMLHiddenField"];
             if (!string.IsNullOrEmpty(message))
                lblHTMLHiddenField.Text = message;
         protected void command_that_postsback(object sender, EventArgs e)
            HTMLHiddenField.Text = uploadHTMLHiddenField.Text;

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.