我在 ASCX 上有一个链接,我想做的是有一个文件下载提示而不做弹出窗口。
例子:
<a href="download.aspx">Download</a>
然后在 Download.aspx Page_Load 我有:
Dim dataAs String = "test"
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" & "test.dat")
Response.AddHeader("Content-Length", achData.Length.ToString())
Response.ContentType = "text/plain"
Response.Write(data)
Response.End()
这是正确的方法吗?我的另一种方法是将代码放在 ASCX 的后面
<asp:button text="download" id="theButton" />
.vb
Public Sub theButton_Click()
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" & "test.dat")
Response.AddHeader("Content-Length", achData.Length.ToString())
Response.ContentType = "text/plain"
Response.Write(data)
Response.End()
End Sub