的JavaScript加入我不是很熟練的ASP.NET和我試圖文件:在同一時間下載ASP.NET通過下載客戶端事件處理
-
上一個aspx網站
- 更新UI元素
- 文件
我有這個JS功能:
function downloadURL(url) {
var hiddenIFrameID = 'hiddenDownloader',
iframe = document.getElementById(hiddenIFrameID);
if (iframe === null) {
iframe = document.createElement('iframe');
iframe.id = hiddenIFrameID;
iframe.style.display = 'none';
document.body.appendChild(iframe);
}
iframe.src = url;
};
,這個按鈕服務器控件:
<asp:Button runat="server" ID="Button1" Content="DOWNLOAD" OnClick="Button1_Click" />
在事件處理我只需撥打:
//更新UI
textBoxXY.Text = "Text after file download";
ClientScript.RegisterStartupScript(typeof(MyPage), "myDownloadKey", "downloadURL(" + ResolveUrl("~/MyDownloadHandler.ashx") + ");", true);
你覺得這種做法的是什麼。它似乎工作,但...
但它需要你到另一個網頁,還是?我需要做回發來更新UI元素。 –
可能您不需要回發帖子,您可以創建參數以便在客戶端上下載哪個文件。但是,如果你需要發回帖子,那麼你可以直接發送他的文件,而不是重新加載頁面。 – Aristos