Click here to Skip to main content
13,149,099 members (55,924 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
heyy .. I am using a fileupload contol..My problem is when I select the file from file upload and after that I clicked a button ..then my upload file path showing in fileupload control is disappear....

plz tell me what to doo..?
Posted 7-Jan-13 23:42pm
Comments
Zafar Sultan 8-Jan-13 6:03am
   
Post your code.
aravindnass 8-Jan-13 6:13am
   
<asp:FileUpload ID="fluNoticeUpload" runat="server" CssClass="textbox" />

and a button is used in another purpose
Zafar Sultan 8-Jan-13 6:18am
   
Are you using updatepanel? Also, what is the code for button's onclick event?
aravindnass 9-Jan-13 0:57am
   
not using updatepanel...but my button is for another purpose(I have separate button for fileupload) ..My problem is ..when I select the file in fileupload and click a button (it is place for other purpose..not for file uploading..) so that button cause prblm..the selected file is disappear...
Pallavi waikar 8-Jan-13 6:10am
   
is that button is server control i.e <asp.Button
that's why on click it reload the page
aravindnass 9-Jan-13 4:18am
   
I read a article in code project ie.("How to Maintain FileUpload Control’s State after PostBack") in that I tried its working....but in that a label1 is used to show that file path....But I want show the filepath not in the label,but show on the fileupload ctrl
http://www.codeproject.com/Tips/101834/How-to-Maintain-FileUpload-Control-s-State-after-P
ryanb31 8-Jan-13 7:58am
   
Your button is likely doing a postback and your losing the file. Why are you clicking a button?
aravindnass 9-Jan-13 0:08am
   
I hava a button near to fileupload ctrl..but that button is used for other purpose
...it is not related with file upload ctrl..but both are in same page..
aravindnass 9-Jan-13 4:18am
   
I read a article in code project ie.("How to Maintain FileUpload Control’s State after PostBack") in that I tried its working....but in that a label1 is used to show that file path....But I want show the filepath not in the label,but show on the fileupload ctrl
http://www.codeproject.com/Tips/101834/How-to-Maintain-FileUpload-Control-s-State-after-P
aravindnass 9-Jan-13 4:18am
   
I read a article in code project ie.("How to Maintain FileUpload Control’s State after PostBack") in that I tried its working....but in that a label1 is used to show that file path....But I want show the filepath not in the label,but show on the fileupload ctrl
http://www.codeproject.com/Tips/101834/How-to-Maintain-FileUpload-Control-s-State-after-P
Pallavi waikar 9-Jan-13 5:53am
   
i go through the FileUpload properties there not any such property to which u can set filepath to it.....it is server control that's why on page reload browse filename is not present on control
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

.then my upload file path showing in fileupload control is disappear....
That's as designed as per fileupload control. The filepath is not retained through postbacks.
  Permalink  
Comments
aravindnass 9-Jan-13 0:56am
   
but my button is for another purpose(I have separate button for fileupload) ..My problem is ..when I select the file in fileupload and click a button (it is place for other purpose..not for file uploading..) so that button cause prblm..the selected file is disappear...
Sandeep Mewara 9-Jan-13 1:06am
   
Button does a postback and hence the fileupload control looses the path. If you want to keep fileupload out of it, try XMLHttepRequest on button click from client side instead of server submit or see if using Update panel around button and related controls help (fileupload outside update panel)
aravindnass 9-Jan-13 4:17am
   
I read a article in code project ie.("How to Maintain FileUpload Control’s State after PostBack") in that I tried its working....but in that a label1 is used to show that file path....But I want show the filepath not in the label,but show on the fileupload ctrl
http://www.codeproject.com/Tips/101834/How-to-Maintain-FileUpload-Control-s-State-after-P
Sandeep Mewara 9-Jan-13 5:18am
   
If you understand why it is happening, you will know what you 'want' is not correct and you need to design properly to avoid such scenario.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Add an update panel and set a postback trigger to the button on which you are uploading the file

e.g :-


<asp:UpdatePanel ID="UpdatePanel" runat="server">
<Triggers><asp:PostBackTrigger ControlID="btnUpload" /></Triggers>
    <ContentTemplate>
 <asp:FileUpload ID="FileUploadControl" EnableViewState="true" runat="server" />
                                    <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click"
                                        CssClass="inputButton" />
 
    </ContentTemplate>
</asp:UpdatePanel>




Thanks,
  Permalink  
Comments
aravindnass 9-Jan-13 0:56am
   
but my button is for another purpose(I have separate button for fileupload) ..My problem is ..when I select the file in fileupload and click a button (it is place for other purpose..not for file uploading..) so that button cause prblm..the selected file is disappear...
aravindnass 9-Jan-13 4:17am
   
I read a article in code project ie.("How to Maintain FileUpload Control’s State after PostBack") in that I tried its working....but in that a label1 is used to show that file path....But I want show the filepath not in the label,but show on the fileupload ctrl
aravindnass 9-Jan-13 4:17am
   
http://www.codeproject.com/Tips/101834/How-to-Maintain-FileUpload-Control-s-State-after-P
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Whenever a postback is performed on a page, the fileupload control loses its state. That said you can not make it hold your file after postback. That is its behaviour by default. Add the following code in Page Load event and try.

if (Session["UploadedFile"] == null && FileUpload1.HasFile) 
Session["UploadedFile"] = FileUpload1;
else if (Session["UploadedFile"] != null && (! FileUpload1.HasFile)) 
FileUpload1= (FileUpload) Session["UploadedFile"]; 
else if (FileUpload1.HasFile) 
Session["UploadedFile"] = FileUpload1; 
  Permalink  
Comments
aravindnass 9-Jan-13 4:16am
   
I read a article in code project ie.("How to Maintain FileUpload Control’s State after PostBack") in that I tried its working....but in that a label1 is used to show that file path....But I want show the filepath not in the label,but show on the fileupload ctrl
aravindnass 9-Jan-13 4:17am
   
http://www.codeproject.com/Tips/101834/How-to-Maintain-FileUpload-Control-s-State-after-P

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.170924.2 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100