I need to track when a file link is clicked on so I built a server side function that writes to a SQL DB when an anchor tag is clicked. It's not firing or opening the file. Here is my code:
我需要跟踪文件链接何时被单击,因此我构建了一个服务器端函数,在单击锚标记时写入到SQL DB中。它不会启动或打开文件。这是我的代码:
HTML
<a href="pdf/Access2013.pdf#zoom=100" runat="server" onServerClick="AccessFile_Click" target="_blank"><img src="img/pdf_icon.png" border="0" /></a>
SERVER CODE
protected void AccessFile_Click(object sender, EventArgs e)
{
App_Code.bi.LogFileDownload("Access File", Session["UserID"].ToString());
}
1 个解决方案
#1
6
You can use an asp.net LinkButton instead:
你可以使用asp.net链接按钮代替:
<asp:LinkButton ID="MyLink" runat="server" OnClick="AccessFile_Click" Text="Click Here"></asp:LinkButton>
Reference: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.aspx
参考:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.aspx
EDIT: I notice that you also want this to open in a new window. To do that with a LinkButton, see this: http://forums.asp.net/t/1154673.aspx/1
编辑:我注意到你也想在一个新的窗口中打开它。要使用LinkButton,请参见:http://forums.asp.net/t/1154673.aspx/1
Basically, you need to add the following to the server-side event handler:
基本上,您需要向服务器端事件处理程序添加以下内容:
string newWindowUrl = "pdf/Access2013.pdf#zoom=100";
string javaScript =
"<script type='text/javascript'>\n" +
"<!--\n" +
"window.open('" + newWindowUrl + "');\n" +
"// -->\n" +
"</script>\n";
this.RegisterStartupScript("", javaScript);
#1
6
You can use an asp.net LinkButton instead:
你可以使用asp.net链接按钮代替:
<asp:LinkButton ID="MyLink" runat="server" OnClick="AccessFile_Click" Text="Click Here"></asp:LinkButton>
Reference: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.aspx
参考:http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.aspx
EDIT: I notice that you also want this to open in a new window. To do that with a LinkButton, see this: http://forums.asp.net/t/1154673.aspx/1
编辑:我注意到你也想在一个新的窗口中打开它。要使用LinkButton,请参见:http://forums.asp.net/t/1154673.aspx/1
Basically, you need to add the following to the server-side event handler:
基本上,您需要向服务器端事件处理程序添加以下内容:
string newWindowUrl = "pdf/Access2013.pdf#zoom=100";
string javaScript =
"<script type='text/javascript'>\n" +
"<!--\n" +
"window.open('" + newWindowUrl + "');\n" +
"// -->\n" +
"</script>\n";
this.RegisterStartupScript("", javaScript);