下载功能不起作用更新面板内的asp.net [英] Download feature not working within update panel in asp.net
问题描述
我有一个包含Web用户控件一个 FormView控件
。 FormView控件显示了求职者的详细信息。我已经提供了下载简历链接按钮,使管理/人力资源可以下载简历。我把这种控制在包含在UpdatePanel一个aspx页面。一切正常,除了下载链接。
I have a Web User Control containing a FormView
. The formview shows details of job seeker. I have provided a button for "Download Resume" link, so that admin/HR can download the resume. I have placed this control in an aspx page that contains the UpdatePanel. Everything works fine except Download Link.
我已经给上donwload链接按钮,命令和功能与命令相关的开始下载。
I have given a Command on donwload link button and a function is associated with the command to start download.
下面是code我已经实现了 -
Below is the code i have implemented -
//Command on 'Download' link button within FormView
protected void lnkDownload_Command(object sender, CommandEventArgs e)
{
if (e.CommandName.Equals("Download"))
{
StartDownload(e.CommandArgument.ToString());
}
}
//My routine to download document
//sFileInfo contains filepath$==$mimetype
protected void StartDownload(string sFileInfo)
{
string[] d = sFileInfo.ToString().Split((new string[] { "$==$" }), StringSplitOptions.None);
string filename = d[0];
string docType = d[1];
System.IO.FileInfo file = new System.IO.FileInfo(d[0]);
if (file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + d[0]);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = d[1];
Response.WriteFile(file.FullName);
Response.End();
}
else
{
Server.Transfer("~/Mesgbox.aspx?cat=2");
}
}
在code完美地工作,如果更新面板被删除,但如果更新面板被用于生成脚本错误。
The code works perfectly if update panel is removed but generates script errors if update panel is used.
任何建议....?
感谢您分享您的时间。
推荐答案
要启动一整页回发,你添加一个触发回发到你的更新面板:
To initiate a full page postback, you add a postback trigger to your update panel:
<asp:UpdatePanel runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="YourControlID" />
</Triggers>
<ContentTemplate>
.....
这篇关于下载功能不起作用更新面板内的asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!