Solved

Persist the value in file uploader in .net

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

862 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now