asp.net 创建上传进度条
请问在asp.net 中Fileupload控件用来上传文件,但是我想做一个进度条,显示现在完成多少了,请问怎么实现啊,谢谢
最好给我一个c#的例子。
[解决办法]
http://www.chinatcm.net.cn/2965.html
[解决办法]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<title> 无标题页 </title>
<script type= "text/javascript ">
var xmlHttp;
var key;
function createXmlHttpRequest()
{
if(window.ActiveXObject)
xmlHttp=new ActiveXObject( "Microsoft.XMLHTTP ");
else if(window.XmlHttpRequest)
xmlHttp=new XmlHttpRequest();
}
function go()
{
checkDiv();
createXmlHttpRequest();
xmlHttp.onreadystatechange=callback;
xmlHttp.open( "get ", "ProgressBar.aspx?task=create ",true);
xmlHttp.send(null);
}
function callback()
{
if(xmlHttp.readyState==4&&xmlHttp.status==200)
{
setTimeout( "pollServer() ",1000);
}
}
function pollServer()
{
createXmlHttpRequest();
xmlHttp.onreadystatechange=pollCallback;
xmlHttp.open( "get ", "ProgressBar.aspx?task=poll&key= "+key,true);
xmlHttp.send(null);
}
function pollCallback()
{
if(xmlHttp.readyState==4&&xmlHttp.status==200)
{
key++;
var percent=xmlHttp.responseXML.getElementsByTagName( "percent ")[0].firstChild.nodeValue;
var end=loadPercent(percent);
for(var i=1;i <=end;++i)
{
var span=document.getElementById( "block "+i);
span.innerHTML= " ";
span.style.backgroundColor= "gray ";
}
if(end <9)
{
end++;
var span=document.getElementById( "block "+end);
span.innerHTML=percent+ "% ";
setTimeout( "pollServer() ",1000);
}
else
{
document.getElementById( "complete ").innerHTML= "complete ";
document.getElementById( "go ").disabled=false;
}
}
}
function loadPercent(percent)
{
if(percent.length==1)
return 1;
else if(percent.length==2)
return percent.substring(0,1);
return 9;
}
function checkDiv()
{
key=1;
var pb=document.getElementById( "progressBar ");
if(pb.style.visibility== "visible ")
{
clearBar();
document.getElementById( "complete ").innerHTML= " ";
}
else
pb.style.visibility= "visible ";
}
function clearBar()
{
for(var i=1;i <=9;++i)
{
var elem=document.getElementById( "block "+i);
elem.innerHTML= " ";
elem.style.backgroundColor= "white ";
}
}
</script>
</head>
<body>
<h1>
Ajax Progress Bar Example </h1>
Launch long-running process:
<input type= "button " value= "launch " id= "go " onclick= "go(); " />
<p>
<table align= "center ">
<tbody>
<tr>
<td>
<div id= "progressBar " style= "padding: 2px; border: solid black 2px; visibility: hidden ">
<span id= "block1 "> </span> <span id= "block2 "> </span>
<span id= "block3 "> </span> <span id= "block4 "> </span>
<span id= "block5 "> </span> <span id= "block6 "> </span>
<span id= "block7 "> </span> <span id= "block8 "> </span>
<span id= "block9 "> </span>
</div>
</td>
</tr>
<tr>
<td align= "center " id= "complete " style= "height: 21px ">
</td>
</tr>
</tbody>
</table>
</p>
</body>
</html>
昨晚刚写的,cs代码见下帖