简体   繁体   中英

How to avoid fileupload text clearing?

Iam using VS2015. Now Iam preparing a small project in ASP.Net. Iam using a control FileUpload.

ASPX - Page

asp:FileUpload ID="FileUpload1" runat="server" ClientIDMode="Static" onchange="this.form.submit()" BackColor="Purple" style="font:20px calibri; border:5px solid blue; Width:100%; Height:100%;"
 
ASPX.CS PAGELOAD
String MyExcelFile = FileUpload1.PostedFile.FileName;

The problem is after executing this above statement, the FileUpload1 clearing the Text value. So is it possible to display the readed file in FileUpload1.

Note : Iam looking for FileUpload only. It's not required to have Upload button & Label. I need to use FileUpload only but the content of browse textbox should not clear. Thanks again.

You could add a 'upload file' button, while you remove the onchange="this.form.submit()" so the fileupload selection won't cause a postback.

This way, when you click the 'upload file' button, on your event handler (eg. uploadFile_Click function) you'll have Access to the filename in the FileUpload control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM