Solved

Persist the value in file uploader in .net

Posted on 2009-05-09
1
253 Views
Last Modified: 2013-11-08
How can the value of Fileuploader persisted on postback in .net
0
Comment
Question by:KaranGupta
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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