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