让Updatepanel中的控件触发整个页面Postback
GridView被Updatepanel包起来了,但是GridView上有一个Download的ImageButton, 局部刷新的话,无法下载文件, 所以用下面代码注册updatepanel中的download button每次点击都整个页面postback。
Download方法:
for (int i = 0; i < this.GridViewSOPDocument.Rows.Count; i++)
{
ImageButton imageButtonDownload = (ImageButton)this.GridViewSOPDocument.Rows[i].FindControl("ImageButtonDownload");
if (imageButtonDownload != null)
{
((ScriptManager)((VPJQueryMaster)this.Master).FindControl("ScriptManager1")).RegisterPostBackControl(imageButtonDownload);
}
}
{
ImageButton imageButtonDownload = (ImageButton)this.GridViewSOPDocument.Rows[i].FindControl("ImageButtonDownload");
if (imageButtonDownload != null)
{
((ScriptManager)((VPJQueryMaster)this.Master).FindControl("ScriptManager1")).RegisterPostBackControl(imageButtonDownload);
}
}
Download方法:
public void FileDownload(string filePath, string fileName, string systemFileName)
{
FileInfo DownloadFile
= new FileInfo(this.ApplicationPhysicalPath + filePath + "\\" + systemFileName);
if (DownloadFile.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename="
+ HttpUtility.UrlDecode(fileName, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}
else
{
ShowAjaxMessage("msg_public_download_file_does_not_exist");
}
}
{
FileInfo DownloadFile
= new FileInfo(this.ApplicationPhysicalPath + filePath + "\\" + systemFileName);
if (DownloadFile.Exists)
{
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename="
+ HttpUtility.UrlDecode(fileName, System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
Response.WriteFile(DownloadFile.FullName);
Response.Flush();
Response.End();
}
else
{
ShowAjaxMessage("msg_public_download_file_does_not_exist");
}
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步