我在asp.net c#application
中使用了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
控件中显示上传的文件。
请帮帮我!!!
答案 0 :(得分:0)
在您的代码上使用<asp:PostBackTrigger ControlID="btnUpload" />
而不是AsyncPostBackTrigger。
答案 1 :(得分:0)
选择FileUpload
<asp:FileUpload ID="file_upload" class="multi" runat="server" />
在更新面板外部,并将EventName
参数添加到此
<asp:AsyncPostBackTrigger ControlID="btnUpload" />
像这样
<asp:AsyncPostBackTrigger ControlID="btnUpload" EventName="Click" />