Ajax控件不能正常工作

本文关键字:工作 常工作 控件 不能 Ajax | 更新日期: 2023-09-27 18:06:15

我在asp.net c#应用程序中使用了ajax控件

 <div class="uploadfiles">
  <asp:ScriptManager ID="ScriptManager1" runat="server"/>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
 <ContentTemplate>
<asp:FileUpload ID="file_upload" class="multi" runat="server" />
   <br /> 
   <asp:Button ID="btnUpload" runat="server" Text="Upload" onclick="btnUpload_Click"/>
   <asp:Label ID="lblMessage" runat="server" />
    <asp:Panel ID="Panel1" runat="server">
    </asp:Panel>
  </ContentTemplate>
     <Triggers>
     <asp:AsyncPostBackTrigger ControlID="btnUpload" />
     </Triggers>
    </asp:UpdatePanel>

.cs文件

protected void btnUpload_Click(object sender, EventArgs e)
    {
        HttpFileCollection fileCollection = Request.Files;
        for (int i = 0; i < fileCollection.Count; i++)
        {
            HttpPostedFile uploadfile = fileCollection[i];
            string fileName = Path.GetFileName(uploadfile.FileName);
            if (uploadfile.ContentLength > 0)
            {
                uploadfile.SaveAs(Server.MapPath("~/UploadFiles/") + fileName);
                lblMessage.Text += fileName + "Saved Successfully<br>";
                HyperLink dynamHyperLink = new HyperLink();
                dynamHyperLink.Text = fileName.ToString() + "Saved Successfully<br>";
                // hyperlnk.Attributes.Add("href", Server.MapPath("/UploadFiles/") + fileName);
                dynamHyperLink.NavigateUrl = "~/UploadFiles/" + fileName;
                Panel1.Controls.Add(dynamHyperLink);
                //lblMessage.Text= "<a href=" + "/UploadFiles/" + fileName +">"+fileName+"</a>";
            }
        }
    }

当我点击上传按钮时,它不执行btnupload_Click()事件,也不显示Panel1控制中上传的文件。

请帮帮我!!

Ajax控件不能正常工作

在代码中使用<asp:PostBackTrigger ControlID="btnUpload" />而不是AsyncPostBackTrigger

FileUpload

<asp:FileUpload ID="file_upload" class="multi" runat="server" />

,并将EventName参数添加到这个

<asp:AsyncPostBackTrigger ControlID="btnUpload" />
这样的

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