我有一个文件上传控件,可以将图像上传到 SQL Server 2008 数据库,我想通过弹出保存对话框下载它。下载文件的代码执行良好,但当我单击下载链接按钮时没有任何反应。该事件从后面的代码触发。我唯一的猜测是再次导致问题的模态弹出窗口。
<Modalpopup>
</ModalPopup>
<UpdatePanel>
--DetailsView
--------LinkButton(Download)
--DetailsView
</UpdatePanel>
是页面的结构。
<!-- Details View here -->
<asp:DetailsView ID="dvReviewCases" runat="server" Height="50px"
AutoGenerateRows="False" CssClass="dvCSS"
OnDataBound="dvADReviewCases_DataBound"
onpageindexchanging="dvReviewCases_PageIndexChanging" onitemcommand="dvReviewCases_ItemCommand"
>
<Fields>
<asp:TemplateField HeaderStyle-CssClass="dvHeaderStyle" HeaderText="Evidence" ItemStyle-CssClass="dvValueField" >
<ItemTemplate>
<asp:LinkButton ID="btnDownload" runat="server" Text='<%#Eval("evidenceID") %>' CommandName="Download" >
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
代码背后
// Download file from Evidence table
protected void dvReviewCases_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
if (e.CommandName == "Download")
{
String strCaseID = Session["caseID"].ToString();
String strEvidenceID = Session["evidenceID"].ToString();
//Search for evidence file
DbCommand cmd = GetData.CreateCommand("ADGetEvidence");
GetData.AddParameter(cmd, strEvidenceID, "@evidenceID");
GetData.AddParameter(cmd, strCaseID, "@caseID");
GetData.GetResults(cmd);
// Check if datatable has row returned
if (GetData.getTable().Rows.Count > 0)
{
String fileName = "Evidence" + Session["caseID"].ToString();
byte[] file = null;
String fileType = GetData.getTable().Rows[0][1].ToString();
// Typecast resulting row to byte
file = ((byte[])GetData.getTable().Rows[0][0]);
Response.ContentType = fileType;
// Give user option to download file
Response.AddHeader("Content-Disposition","attachment;filename=" + fileName);
Response.BinaryWrite(file);
Response.End();
}
}
}