2
我有一個要求,當用戶點擊一個按鈕時處理(服務器端)大量的數據(文件)。我想在處理每個文件名時顯示正在運行的摘要。我一直試圖用UpdatePanel控件來做,但只有最後一次更新發生。下面是我創建模擬問題,一些簡單的代碼(它應該從1數到10,而是等待5秒,輸出10):如何在處理服務器上的某些內容時更新狀態標籤?
<%@ Page Language="C#" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
ScriptManager1.RegisterAsyncPostBackControl(Button1);
}
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 1; i <= 10; i++)
{
Label1.Text = i.ToString();
System.Threading.Thread.Sleep(500);
UpdatePanel1.Update();
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
有沒有一種方法,使這項工作?或者,也許更好的方法來做到這一點?
在此先感謝,傑森
哇,這絕對是更復雜的比我希望的。由於這是功能,我只打算使用一次然後扔掉(從舊系統遷移到新的數據)我決定現在不擔心它。感謝您的答覆,但可以在未來派上用場。 – Jason