后面的代码会丢失。
我有一个asp:LinkButton,当用户点击然后附加文件将被下载,我也需要知道链接是否被点击。 出于测试目的,我在asp:LinkButton点击事件上放了一个文本框并更改了它的文本。 但文本框文本仍为旧文本,文件正在正常下载。
<asp:LinkButton runat="server" ID="LinkAttachmentView"
ToolTip="Click here to Download the Attachment" Font-Bold="True"
ForeColor="Red" >Click here to View the Attachment
</asp:LinkButton>
这是代码
Protected Sub LinkAttachmentView_Click(sender As Object, e As System.EventArgs) Handles LinkAttachmentView.Click
If HdAttachmentFileName.Value = "" Then
HdAttachmentClicked.Value = "0"
Return
End If
HdAttachmentClicked.Value = "1"
TextBox1.Text = "clicked"
Response.ContentType = ContentType
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(HdAttachmentFileName.Value))
Response.WriteFile(HdAttachmentFileName.Value)
Response.Flush()
Response.End()
HdAttachmentClicked.Value = "1"
TextBox1.Text = "clicked"
End Sub
答案 0 :(得分:0)
我需要的是知道用户是否点击了链接按钮。我只是在linkbutton客户端上添加了一个javascript函数,单击以更新Hidden字段的值。
这是javascript:
function SetClickValue() {
var HdField = document.getElementById("<%=HdAttachmentClicked.ClientID%>");
HdField.value = "1";
}
HTML:
<asp:LinkButton runat="server" ID="LinkAttachmentView"
ToolTip="Click here to Download the Attachment" Font-Bold="True"
ForeColor="Red" onclientclick="SetClickValue()"
>Click here to View the Attachment
</asp:LinkButton>
点击事件现在只是用于下载附件:
Protected Sub LinkAttachmentView_Click(sender As Object, e As System.EventArgs) Handles LinkAttachmentView.Click
If HdAttachmentFileName.Value = "" Then
HdAttachmentClicked.Value = "0"
Return
End If
Response.ContentType = ContentType
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(HdAttachmentFileName.Value))
Response.WriteFile(HdAttachmentFileName.Value)
Response.Flush()
Response.End()
End Sub