我的项目中有一个Handler.ashx,用于向用户显示另存为对话框 我也有一个带有链接按钮的转发器,用于点击并最后显示上部保存为对话框 我把我的转发器放在更新面板里! ItemCommand的代码该转发器的代码如下:
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//The Below Line Does Not Work - Always Is Null
//NewAddedFiles currentItem = (NewAddedFiles)e.Item.DataItem;
HiddenField hfFilePath = (HiddenField)e.Item.FindControl("hfFilePath");
HiddenField hfFileName = (HiddenField)e.Item.FindControl("hfFileName");
HiddenField hfFileSize = (HiddenField)e.Item.FindControl("hfFileSize");
HiddenField hfFileCreationDate = (HiddenField)e.Item.FindControl("hfFileCreationDate");
switch (e.CommandName)
{
case "lbFile_Click":
{
if (Session["User_ID"] != null)
{
DataSet dsDownload = DataLayer.Download.Size_By_UserID_Today(int.Parse(HttpContext.Current.Session["User_ID"].ToString()), DateTime.Now);
if (dsDownload.Tables["Download"].Rows.Count > 0)
{
DataRow drDownload = dsDownload.Tables["Download"].Rows[0];
int SumOfFileSize4Today = int.Parse(drDownload["FileSizSum"].ToString());
if (SumOfFileSize4Today + int.Parse(hfFileSize.Value) <= 1073741824)//1 GB = 1024*1024*1024 bytes = 1073741824 bytes
//if (SumOfFileSize4Today + int.Parse(hfFileSize.Value) <= 100000)
{
DataLayer.Download.InsertRow(
int.Parse(HttpContext.Current.Session["User_ID"].ToString()),
DateTime.Now,
hfFilePath.Value,
hfFileName.Value,
hfFileSize.Value,
DateTime.Parse(hfFileCreationDate.Value)
);
Response.Redirect("~/HandlerForRepeater.ashx?path=" + hfFilePath.Value);
}
else
{
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "YouCanNotDownloadAnyMore_SizeOverload", "YouCanNotDownloadAnyMore_SizeOverload();", true);
}
}
else
{
if (int.Parse(hfFileSize.Value) <= 1073741824)
//if (int.Parse(hfFileSize.Value) <= 100000)
{
DataLayer.Download.InsertRow(
int.Parse(HttpContext.Current.Session["User_ID"].ToString()),
DateTime.Now,
hfFilePath.Value,
hfFileName.Value,
hfFileSize.Value,
DateTime.Parse(hfFileCreationDate.Value)
);
Response.Redirect("~/HandlerForRepeater.ashx?path=" + hfFilePath.Value);
}
else
{
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "YouCanNotDownloadAnyMore_SizeOverload", "YouCanNotDownloadAnyMore_SizeOverload();", true);
}
}
}
else
{
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "plzLoginFirst_ForDownload", "plzLoginFirst_ForDownload();", true);
}
break;
}
default:
{
break;
}
}
}
}
此代码的重要部分是:
Response.Redirect("~/HandlerForRepeater.ashx?path=" + hfFilePath.Value);
因为此行回调永远不会结束,当保存为对话框时,转发器区域进入thinkink模式并被禁用!
我该如何解决这个问题?
答案 0 :(得分:1)
我对UpdatePanels并不完全熟悉,但是当你说'回调永远不会结束,并且当对话框出现时保存,转发器区域进入思维模式并被禁用'时,我认为你已经自己回答了这个问题。
发生的事情是您没有返回对您的请求的页面响应,而是从您的页面向服务器发出请求,该请求重定向到您的处理程序,我猜测它正在响应文件下载。您请求的页面现在已过时,如果您想继续使用此页面,则需要将其作为响应返回。
您可以考虑的两个选项是: