我在ASCX上有一個鏈接,我想要做的就是不用彈出窗口就進行文件下載提示。在沒有彈出窗口的情況下在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
我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 –
你的問題需要更多細節。你想讓用戶下載一個文件或你想要的文字嗎? 來源是一個文件或只是你的數據,實際上是一個字符串。請註明 – Kiarash
我不明白這個功能的用途是什麼theButton_Click –