我将尝试使用 <a> 标签强制下载 PDF 文件。
这是我的代码:
<a ID="personal_training_form" class="pdfcalltoaction" OnServerClick="personal_training_form_Click" runat="server">PERSONAL TRAINING FORM</a>
我的代码后端:
public void personal_training_form_Click(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=PersonalTrainingForm.pdf");
Response.TransmitFile("~/programs/PERSONAL_TRAINING_FORM_to_mail.pdf");
Response.End();
}
看起来页面只是在刷新,没有文件被下载。
编辑:
所以我尝试将其更改为LinkButton,但仍然出现类似的问题。
<asp:LinkButton ID="personal_training_form" CssClass="pdfcalltoaction" runat="server" OnClick="personal_training_form_Click">Personal Training Form</asp:LinkButton>