当我将 FileUpload 放入更新面板时,它没有出现在页面中

When I put FileUpload inside update panel it does not appear in page

当我把它放在更新面板里时,文件上传没有出现。我需要将它添加到更新面板中,因为 FileUpload.HasFile Always returns false

我的html代码:

   <tr>
    <asp:UpdatePanel ID="UpdatePanel1"  runat="server">
       <ContentTemplate>
    <td>
       <asp:Button ID="btnUpload" runat="server" onclick="Button1_Click"   
         Text="Upload" />
                    </td>
               <asp:FileUpload ID="FUCivilID" runat="server" />
          <asp:Image ID="imgViewFile" runat="server" Height="60px"  
                     Width="275px" />
                </ContentTemplate>
              <Triggers>
  <asp:AsyncPostBackTrigger ControlID="Button1_Click" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>      
     </tr>

上传按钮代码:

if (FUCivilID.HasFile) 
{
   string ext = Path.GetExtension(FUCivilID.FileName);
   if (ext == ".jpg" || ext == ".png" || ext == ".gif")
   { 
      imgViewFile.ImageUrl = Server.MapPath("~/CivilIds/" + FUCivilID.FileName);
      FUCivilID.SaveAs(MapPath("~/CivilIds/" + FUCivilID.FileName));
      imgViewFile.ImageUrl = "~/CivilIds/" + FUCivilID.FileName;
   }

页面加载中:

Page.Form.Attributes.Add("enctype", "multipart/form-data");

fileUpload 控件与 updatePanel (Microsoft) 有一些问题,请尝试更改您的

 <asp:AsyncPostBackTrigger ControlID="Button1_Click" EventName="Click" />

对于

<asp:PostBackTrigger ControlID="Button1_Click" EventName="Click" />

To use a FileUpload or HtmlInputFile control inside an UpdatePanel control, set the postback control that submits the file to be a PostBackTrigger control for the panel. The FileUpload and HtmlInputFile control can be used only in postback scenarios.

还有其他的选择,我用过FUA成功