The Fileupload.hasfile property is always False

Source: Internet
Author: User
Tags function prototype

The HasFile property gets a value that indicates whether the FileUpload control contains the file to upload. Use this property to verify that the file exists before performing an operation on the file to be uploaded. For example, use the HasFile property to verify that a file exists before calling the SaveAs method to save the file to disk. If HasFile returns True, the SaveAs method is invoked. If it returns false, a message is displayed to the user indicating that the control does not contain a file.
The solution is as follows:
Programme I,
If you set the ScriptManager enablepartialrending to False, you can upload it correctly, this method is the simplest, but there will be a flaw, that is, multiple UpdatePanel on the same page cannot be refreshed alone.
In addition, when there is validator in your UpdatePanel, it can cause the whole page to postback, which seems to be a bug in Altas.
Programme II,
1. Use UpdatePanel in the main page, then UpdatePanel inside not fileupload control, but an IFRAME
2: This iframe is linked to a new page with a FileUpload control on that page.
3: After uploading, tell the home page to upload the results

Direct use of FileUpload example: In this example, the server can not find uploaded files.
<atlas:updatepanel id= "Up1" mode= "Conditional" runat= "Server" >
<ContentTemplate>
<asp:fileupload id= "FileUpload1" runat= "Server"/>
<asp:button id= "Button1" runat= "Server" text= "button" onclick= "Button1_Click"/>
<ContentTemplate>
<atlas:UpdatePanel>
1. Create a new home page default.aspx in the appropriate location, place an upload attachment UpdatePanel area
<atlas:updatepanel id= "up_attachment" mode= "Conditional" runat= "Server" >
<ContentTemplate>
<iframe id= "File" name= "file" src= "attachment.aspx" ><iframe>
<ContentTemplate>
<atlas:UpdatePanel>
2: New Upload File page attachment.aspx, then put the FileUpload control
<div>
<asp:fileupload id= "FileUpload1" runat= "Server"/>
<asp:button id= "Button1" runat= "Server" text= "OK" onclick= "Button1_Click"/>
<div>
3: Inside the attachment.aspx, upload files after the Call home page JS, report upload situation. This is the function prototype:
<script> Window.top.callBack (fileName); <script>
4:default.aspx The home page adds this function, processing the return value
<script>
function CallBack (fileName)
{document.getElementById (' Attach1 '). Innerhtml=filename}
<script>



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.