我正在尝试在我的网站上实现 AjaxUploadControl 功能,但它不会触发 OnUploadComplete 方法。相反,它只是说文件已上传 100%,但文件不在指定的文件夹中。我在 OnUploadComplete 方法中设置了断点,并且能够确定永远不会到达此方法。当“取消”按钮显示时,它似乎跳入了无限循环,但一旦尝试上传文件,屏幕上的任何按钮都不可点击。
.aspx 页面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AjaxTest.aspx.cs" Inherits="AjaxTest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
<div>
<ajaxToolkit:AjaxFileUpload ID="ajaxUpload1" runat="server" OnUploadComplete="ajaxUpload1_OnUploadComplete" />
</div>
</form>
</body>
</html>
代码隐藏文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class AjaxTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ajaxUpload1_OnUploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
string filePath = "~/SiteImages/" + e.FileName;
ajaxUpload1.SaveAs(MapPath(filePath));
}
}
非常感谢您的帮助!