Solved

Persist the value in file uploader in .net

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 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

13 Experts available now in Live!

Get 1:1 Help Now