asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

ASP.NET实现进度条


发布日期:2018年12月11日
 
ASP.NET实现进度条

终于找到一个ASPNET实现进度条的例子

建立一个WEB工程添加新项>HTML页面命名为内容如下

<!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN transitionaldtd>

<html xmlns= id=mainWindow>

<head>

<title>无标题页</title>

<script language=javascript>

function SetPorgressBar(pos)

{

//设置进度条居中

var screenHeight = window[mainWindow]offsetHeight;

var screenWidth = window[mainWindow]offsetWidth;

ProgressBarSidestylewidth = Mathround(screenWidth / );

ProgressBarSidestyleleft = Mathround(screenWidth / );

ProgressBarSidestyletop = Mathround(screenHeight / );

ProgressBarSidestyleheight = px;

ProgressBarSidestyledisplay = ;

//设置进度条百分比

ProgressBarstylewidth = pos + %;

ProgressTextinnerHTML = pos + %;

}

//完成后隐藏进度条

function SetCompleted()

{

ProgressBarSidestyledisplay = none;

}

</script>

</head>

<body>

<div id=ProgressBarSide >

<div id=ProgressBar ></div>

<div id=ProgressText ></div>

</div>

</body>

</html>

后台代码Defaultaspxcs

using System;

using SystemData;

using SystemConfiguration;

using SystemWeb;

using SystemWebSecurity;

using SystemWebUI;

using SystemWebUIWebControls;

using SystemWebUIWebControlsWebParts;

using SystemWebUIHtmlControls;

using SystemThreading;

using SystemIO;

public partial class _Default : SystemWebUIPage

{

private void beginProgress()

{

//根据显示进度条界面

string templateFileName = PathCombine(ServerMapPath() );

StreamReader reader = new StreamReader(@templateFileNameSystemTextEncodingGetEncoding(GB));

string html = readerReadToEnd();

readerClose();

ResponseWrite(html);

ResponseFlush();

}

private void setProgress(int percent)

{

string jsBlock = <script>SetPorgressBar( + percentToString() + ); </script>;

ResponseWrite(jsBlock);

ResponseFlush();

}

private void finishProgress()

{

string jsBlock = <script>SetCompleted();</script>;

ResponseWrite(jsBlock);

ResponseFlush();

}

private void Page_Load(object sender SystemEventArgs e)

{

beginProgress();

for (int i = ; i <= ; i++)

{

setProgress(i);

//此处用线程休眠代替实际的操作如加载数据等

SystemThreadingThreadSleep();

}

finishProgress();

}

}

               

上一篇:微软最新ASP.NETMVC框架Beta版技术细节

下一篇:Asp.NET自定义DataGrid控件