Solved

Persist the value in file uploader in .net

Posted on 2009-05-09
1
254 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

728 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