我正在用檔案附件在 asp.net 中創建一個 web 表單專案。我放置了一個標簽控制元件來指示行程的進度(例如,“正在啟動行程”,幾秒鐘后變為“正在讀取第一個記錄檔案”,最終標簽“檔案行程完成!”)。我怎樣才能實作這個例程?那需要重繪 頁面嗎?
期待你的回復。謝謝你。
uj5u.com熱心網友回復:
好的,開始程序或者說甚至是這樣一個不錯的 gif:

所以,第一條訊息,或者影片是沒有問題的。
附加資訊?嗯,這要困難得多,除非你偽造這個。
因此,舉一個簡單的例子,假設我們有一個需要很長時間(比如 4 秒)的按鈕。
所以,我們說這個按鈕:
<asp:Button ID="cmdProcess" runat="server" Text="Big process"
CssClass="btn"
OnClick="cmdProcess_Click"
OnClientClick="showwait()" />
<script>
function showwait() {
$("#MyProgress").show()
}
</script>
<div id="MyProgress" style="display:none">
<h2>Working</h2>
<img src="../Content/wait2.gif" style="height: 67px; width: 80px" />
</div>
因此,當您單擊上面的按鈕時,它將運行客戶端例程(顯示我們的 div),然后是服務器端代碼,如下所示:
protected void cmdProcess_Click(object sender, EventArgs e)
{
Thread.Sleep(4000);
}
所以,你有這個:

當您單擊該按鈕時,您會看到以下 4 秒鐘:

所以,這很容易,因為我們只顯示那個 div。
還有獎金?好吧,既然按鈕是回發的,那么當按鈕代碼完成后,客戶端當然會重新重繪 ,現在我們的“延遲div”不再顯示了。
但是,如果您想說要更改的訊息,請說:
第 1 部分作業......
然后作業第 2 部分 .....
Then I would start that "long" process as a web method. This can be difficult, since any web method you call does NOT have use of all the page controls.
often, you can (could) on the post back, fire off a new thread, and pass values, and then have a timer (client side) that calls a web method that returns the status.
And that timer would have to "check" some status value (say every one second), and get some value from the server. Since we don't have (and really can't have) additonal post-backs, then that web method will have to get that status message. That web method will have to return some status PROBABLY from session().
So display of "one" message when you click a button? Very easy.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/325417.html
上一篇:重定向到asp.net中的上一頁
