Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
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

.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.
 
Share this answer
 
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.
Add an update panel and set a postback trigger to the button on which you are uploading the file

e.g :-


XML
<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,
 
Share this answer
 
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
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.

C#
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; 
 
Share this answer
 
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900