Solved

Persist the value in file uploader in .net

Posted on 2009-05-09
1
251 Views
Last Modified: 2013-11-08
How can the value of Fileuploader persisted on postback in .net
0
Comment
Question by:KaranGupta
1 Comment
 
LVL 2

Accepted Solution

by:
clinton_cunningham earned 500 total points
ID: 24343238
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:


     
HTML:
 
<div>
             <asp:FileUpload ID="uploadHTMLHiddenField" runat="server"></asp:Label>
 .            <input id="HTMLHiddenField" type="hidden" name="HTMLHiddenField"/>
         </div>
 
 
   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

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question