我认为这更容易......
我有一个带有target=”_blank”
的asp:超链接控件,指向我希望用户下载的文件。我的计划是跟踪用户点击此链接的次数。
我想将它放在ajax更新面板中,以捕获回发并避免整页刷新。
但是,超链接没有onClick
方法。
另一方面,我可以使用内置linkbutton
的{{1}}。但是在新窗口中打开文件会更难...而且我还需要做类似的事情:
onClick
但我听说上面的方法在 PPT,PPTX,PPS,PPSX ...
方面存在一些问题你对此有何看法? 怎么以及为什么,你会这样做吗?
答案 0 :(得分:5)
您可能希望实施IHttpHandler来跟踪您的下载,例如this article中所示。
基本上你的处理程序的ProcessRequest()方法看起来像这样:
public void ProcessRequest(HttpContext context)
{
string file = context.Request.QueryString["file"];
// set content type and header (PDF in this example)
context.Response.ContentType = "application/pdf";
context.Response.AddHeader(
"Content-Disposition", "attachment; filename=" + file);
// assuming all downloadable files are in ~/data
context.Response.WriteFile(Server.MapPath("~/data/" + file));
context.Response.End();
}
然后你下载文件的超链接就像这样:
<a href="/MyApp/MyHandler.ashx?file=someFile.pdf">...</a>
答案 1 :(得分:1)
您可以将onclick
添加到asp超链接,如下所示:
aHyperlinkControl.Attributes.Add("onclick", "jsCallToSendCountToServer();");