update panel with file upload

牧云@^-^@ 提交于 2019-12-12 14:06:34

问题


<asp:FileUpload runat="server" ID="uploadCertification" />
<asp:Button runat="server" ID="btntext" OnClick="btntext_Click" />

Code

uploadCertification.PostedFile.SaveAs(serverPathImage + "\\CertificationCompany\\as.td");

this code work fine but when

 <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
      <asp:UpdatePanel ID="UpdatePanel3" runat="server"><ContentTemplate>
     <asp:FileUpload runat="server" ID="uploadCertification" />
      <asp:Button runat="server" ID="btntext" OnClick="btntext_Click" />
</ContentTemplate></asp:UpdatePanel>

Code

 uploadCertification.PostedFile.SaveAs(serverPathImage + "\\CertificationCompany\\as.td");

this line say error: Object reference not set to an instance of an object.


回答1:


Take a look at using a PostBackTrigger within your UpdatePanel:

PostBackTrigger

The above MSDN article contains a code listing for using a PostBackTrigger with a FileUpload control.

Other approaches available to you are to use the iframe approach (mentioned in one of the other answers) or to use one of the many third party components out there which make use of javascript and flash to upload files (Find links to a couple of the more popular ones below)

Uploadify

SWFUpload




回答2:


Unfortunatly the UpdatePanel does not work with some controls, notably the FileUpload control. I believe there is a problem with uploading files using javascript. Have a look here http://msdn.microsoft.com/en-us/library/bb386454.aspx for a better explaination.

I have got around this problem in the past using an Iframe on a seperate page that does the upload. http://www.codeproject.com/KB/aspnet/FileUploadingWithLoading.aspx



来源:https://stackoverflow.com/questions/7042632/update-panel-with-file-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!