更新面板文件上传文件上传、面板

2023-09-10 19:37:45 作者:天涯我独行

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

code

Code

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

这code工作正常,但当

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

Code

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

这行说错误:对象引用不设置到对象的实例

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

推荐答案

看看使用PostBackTrigger您的UpdatePanel内:

Take a look at using a PostBackTrigger within your UpdatePanel:

PostBackTrigger

以上MSDN文章包含一个code房源为使用PostBackTrigger用FileUpload控件。

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

可供您使用其它方法是使用的iframe方法(在其他的答案中的一个提到的),或者使用许多第三方组件在那里它使用JavaScript和Flash中的一个上传文件(找到链接到一个情侣以下的较受欢迎的)

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的