让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");
}
}