利用Asp.Net回調(diào)機(jī)制實(shí)現(xiàn)進(jìn)度條

首先,在HTML文檔中加入如下代碼:
<div>
<table class="statusTable">
<tr>
<td id="progress1">
</td>
<td id="progress2">
</td>
<td id="progress3">
</td>
<td id="progress4">
</td>
<td id="progress5">
</td>
<td id="progress6">
</td>
<td id="progress7">
</td>
<td id="progress8">
</td>
<td id="progress9">
</td>
<td id="progress10">
</td>
</tr>
</table>
<asp:Label ID="Label1" runat="server" ForeColor="Red" Text="0"></asp:Label>
</div>
<div>
<input id="btnRequest" type="button" value="請(qǐng)求" onclick="Request()" />
<input id="btnStop" type="button" value="停止" disabled="disabled" onclick="Stop()" />
</div>
Js部分加入如下Js代碼:
<script language="javascript" type="text/javascript">
var idx = 0;
var progressTimer;
var progressInterval = 1000;
function Request()
{
document.getElementById("btnStop").disabled = "";
document.getElementById("btnRequest").disabled = "disabled";
if(idx >= 10)
{
Clear();
return;
}
var arg = idx;
<%= ClientScript.GetCallbackEventReference(this, "arg", "GetMsgBack",null) %>;
idx++;
progressTimer = setTimeout('Request()',progressInterval);
}
function GetMsgBack(result)
{
document.getElementById('progress'+idx).style.backgroundColor = 'blue';
var status = Number(result) * 10;
document.getElementById("Label1").innerHTML = status + "%";
}
function Stop()
{
clearTimeout(progressTimer);
Clear();
}
function Clear()
{
idx = 0;
document.getElementById("btnStop").disabled = "disabled";
document.getElementById("btnRequest").disabled = "";
document.getElementById("Label1").innerHTML = "0";
for (var i = 1; i <= 10; i++)
document.getElementById('progress' + i).style.backgroundColor = 'transparent';
}
</script>
css樣式文件中加入如下代碼:
.statusTable
{
width:100px;
border:solid 1px #000000;
padding-bottom:0px;
margin-bottom:0px;
}
.statusTable td
{
height:20px;
}
Asp.Net服務(wù)端實(shí)現(xiàn)回調(diào)代碼如下:
public partial class DigitStatus : System.Web.UI.Page, ICallbackEventHandler
{
private string AspEventArgs;
protected void Page_Load(object sender, EventArgs e)
{
}
public void RaiseCallbackEvent(string EventArgs)
{
AspEventArgs = EventArgs;
}
public string GetCallbackResult()
{
int i = Convert.ToInt32(AspEventArgs);
i++;
return i.ToString();
}
}
這樣,一個(gè)簡(jiǎn)易的進(jìn)度條就實(shí)現(xiàn)了,運(yùn)行即可得到如頁(yè)首處的效果。
- Asp.net基于ajax和jquery-ui實(shí)現(xiàn)進(jìn)度條
- ASP.NET實(shí)現(xiàn)進(jìn)度條效果
- asp.net mvc 實(shí)現(xiàn)文件上傳帶進(jìn)度條的思路與方法
- asp.net文件上傳帶進(jìn)度條實(shí)現(xiàn)案例(多種風(fēng)格)
- asp.net單文件帶進(jìn)度條上傳的解決方案
- Asp.Net 無(wú)刷新文件上傳并顯示進(jìn)度條的實(shí)現(xiàn)方法及思路
- asp.net 生成靜態(tài)頁(yè)時(shí)的進(jìn)度條顯示
- ASP.NET技巧:教你制做Web實(shí)時(shí)進(jìn)度條
- ASP.NET?MVC使用jQuery?ui的progressbar實(shí)現(xiàn)進(jìn)度條
相關(guān)文章
AspNetPager分頁(yè)控件定義及應(yīng)用樣式示例介紹
AspNetPager分頁(yè)控件想必大家并不陌生吧,在本文將為大家詳細(xì)介紹下此控件的css樣式定義,感興趣的朋友可以參考下2013-10-10viewstate和datatable動(dòng)態(tài)錄入數(shù)據(jù)示例
這篇文章主要介紹了viewstate和datatable動(dòng)態(tài)錄入數(shù)據(jù)示例,需要的朋友可以參考下2014-02-02ASP.NET?MVC通過(guò)勾選checkbox更改select的內(nèi)容
這篇文章介紹了ASP.NET?MVC通過(guò)勾選checkbox更改select內(nèi)容的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-09-09.net core版 文件上傳/ 支持批量上傳拖拽及預(yù)覽功能(bootstrap fileinput上傳文件)
本篇內(nèi)容主要解決.net core中文件上傳的問(wèn)題 開(kāi)發(fā)環(huán)境:ubuntu+vscode.本文給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧2017-03-03IP地址與整數(shù)之間的轉(zhuǎn)換實(shí)現(xiàn)代碼(asp.net)
把這個(gè)整數(shù)轉(zhuǎn)換成一個(gè)32位二進(jìn)制數(shù)。從左到右,每8位進(jìn)行一下分割,得到4段8位的二進(jìn)制數(shù),把這些二進(jìn)制數(shù)轉(zhuǎn)換成整數(shù)然后加上”。”就是這個(gè)ip地址了2012-09-09使用HtmlAgilityPack XPath 表達(dá)式抓取博客園數(shù)據(jù)的實(shí)現(xiàn)代碼
使用HtmlAgilityPack XPath表達(dá)式來(lái)抓取博客園數(shù)據(jù)使用WebClient 下載數(shù)據(jù),HtmlAgilityPack XPath表達(dá)式解析數(shù)據(jù),并綁定到Repeater控件2011-12-12asp.net實(shí)現(xiàn)多個(gè)文件同時(shí)下載功能
這篇文章主要為大家詳細(xì)介紹了asp.net實(shí)現(xiàn)多個(gè)文件同時(shí)下載功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04asp.net 2.0多語(yǔ)言網(wǎng)站解決方法
asp.net 2.0中的App_GlobalResources可以用來(lái)解決本地化的問(wèn)題,程序會(huì)根據(jù)瀏覽器的語(yǔ)言首選項(xiàng)自動(dòng)判斷顯示出本地化的界面。2008-09-09