FileUpload cannot assign values.

Source: Internet
Author: User

FileUpload cannot assign values.

FileUpload cannot be assigned a value.

 

Prepared by: CC Dad

 

November

 

Today, I want to share with you how to deal with the problem that the fileupload control cannot be assigned a value. If you are interested, you can discuss and learn it together. Otherwise, you can skip it.

 

I believe you have used the fileupload control in your usual asp.net development project. For example

When a user uploads an attached file, the address bar of fileupload will display the upload path normally. However, after page refreshing, the file selected before FileUpload is blank. You need to select a new file, very troublesome. In addition, after the upload, the address bar is cleared again when the data is updated and the screen is loaded.

 

Moreover, for security reasons, the fileupload control cannot be assigned a value. However, we can use other methods to handle the problem:

For example, you can add a textbox box to set the width of the fileupload control to 0,

<Td class = "TableItem"> <asp: TextBox ID = "txtFileName" runat = "server"/>

<Asp: FileUpload ID = "FileUpload" runat = "server" Width = "0px"/>
</Td>
<Td class = "TableItem">
<Asp: Button ID = "btnUpload" runat = "server" Text = "Upload" class = "Button" OnClick = "btnUpload_Click"/>
<Asp: Button ID = "btnDownload" runat = "server" Text = "Download" class = "Button" onclick = "btnDownload_Click"/>
<Asp: Button ID = "btnDelete" runat = "server" Text = "Delete" class = "Button" onclick = "btnDelete_Click"/>

</Td>

 

Add the following code to pageload:

This. FileUpload. Attributes. Add ("onchange", "document. getElementById ('" + txtFileName. ClientID + "'). value = this. value ");

In the onchange event of FileUpload, assign the selected file path to TextBox. The combination of TextBox and fileupload with a width of 0 becomes the pseudo FileUpload. TextBox can be assigned a value at will, page refresh will not be cleared. in this way, the problem will not be solved.

 

 

Join the technology sharing Group

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.