通过文件上传更新面板
<asp:FileUpload runat="server" ID="uploadCertification" />
<asp:Button runat="server" ID="btntext" OnClick="btntext_Click" />
编写
uploadCertification.PostedFile.SaveAs(serverPathImage + "\\CertificationCompany\\as.td");
此代码工作正常,但是当
<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>
编写
uploadCertification.PostedFile.SaveAs(serverPathImage + "\\CertificationCompany\\as.td");
此行时显示错误:对象引用未设置为对象的实例。
<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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看一下在 UpdatePanel 中使用 PostBackTrigger:
PostBackTrigger< /a>
上述 MSDN 文章包含将 PostBackTrigger 与 FileUpload 控件一起使用的代码列表。
您可以使用的其他方法是使用 iframe 方法(在其他答案之一中提到)或使用许多第三方组件之一,这些组件利用 javascript 和 flash 上传文件(查找几个以下是更受欢迎的)
Uploadify
SWF上传
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
不幸的是,UpdatePanel 不适用于某些控件,特别是 FileUpload 控件。我相信使用 javascript 上传文件有问题。
看看这里 http://msdn.microsoft.com/en-us/library /bb386454.aspx
为了更好的解释。
我过去曾在单独的页面上使用 Iframe 来进行上传,从而解决了这个问题。 http://www.codeproject.com/KB/aspnet/FileUploadingWithLoading.aspx
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