Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 at 8-Jan-13 6:03am
   
Post your code.
aravindnass at 8-Jan-13 6:13am
   
<asp:FileUpload ID="fluNoticeUpload" runat="server" CssClass="textbox" />
 
and a button is used in another purpose
Zafar Sultan at 8-Jan-13 6:18am
   
Are you using updatepanel? Also, what is the code for button's onclick event?
aravindnass at 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 at 8-Jan-13 6:10am
   
is that button is server control i.e
aravindnass at 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 at 8-Jan-13 7:58am
   
Your button is likely doing a postback and your losing the file. Why are you clicking a button?
aravindnass at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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 at 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
0 Schatak 394
1 OriginalGriff 340
2 _Amy 115
3 Abhijit Ghosh (Subho) 115
4 Andreas Gieriet 100
0 OriginalGriff 7,107
1 Sergey Alexandrovich Kryukov 5,623
2 Maciej Los 3,504
3 Peter Leow 3,373
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 9 Jan 2013
Copyright © CodeProject, 1999-2014
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