我从数据库返回数据表,并在运行时将其作为表格绘制,如下面的代码
string Link = dt_Materials.Rows[x]["Link"].ToString();
material_data += "<td><div style='font-family:Tahoma; font-size:15px; text-align:center;'>" + ClassPeriod + "</div></td>";
material_data += "<td><a onclick='mona(" + Link + ");'><img style='margin-top:5px;' width='20' height='20' src='../Contents/images/trash.png' title='delete album'/></a></td>";
当用户点击图片时,应该根据该功能的链接下载文件
public void mona(string strRequest)
{
try
{
// string strRequest = Request.QueryString["file"]; //-- if something was passed to the file querystring
if (strRequest != "")
{
string path = Server.MapPath("materialFolder"+ strRequest); //get file object as FileInfo
System.IO.FileInfo file = new System.IO.FileInfo(path); //-- if the file exists on the server
if (file.Exists) //set appropriate headers
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}
else
{
Response.Write("This file does not exist.");
}
}
else
{
//nothing in the URL as HTTP GET
Response.Write("Please provide a file to download.");
}
}
catch (Exception ex)
{
}
}
我想知道为什么当我点击时,没有发生任何事件