使用 Asp.Net Response.Write() 製作即時進度條

來源:互聯網
上載者:User

標籤:

準備:

  一個 StudyResponse.aspx 頁面和 CodeBehind 檔案。

Web 頁面中的內容如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StudyResponse.aspx.cs" Inherits="WebApplication1.StudyResponse" %>

Web 頁面的 CodeBehind 中的代碼如下:

namespace WebApplication1{    public partial class StudyResponse : System.Web.UI.Page    {        private readonly StringBuilder _builder = new StringBuilder();        protected void Page_Load( object sender, EventArgs e )        {            for (var i = 1; i <= 50; i++)            {                Thread.Sleep(50);                _builder.Clear();                if (i == 1)                {                    _builder.Append("<html><head></head>  <body>");                    _builder.Append("<script src=‘FileUpload.js‘ type=‘text/javascript‘></script>");                    _builder.AppendLine("<div style=‘width: 202px; height: 22px; border: 1px solid #0094ff;‘>");                    _builder.AppendLine("<div id=‘progress‘ style=‘width: 0; height: 20px; background-color: #ccc; margin: 1px;‘></div>");                    _builder.AppendLine("</div>");                    _builder.AppendLine("<script type=‘text/javascript‘>");                    _builder.AppendLine("_setProgress(" + i * 4 + ");");                    _builder.AppendLine("</script>");                    _builder.Append("</body></html>");                }                else                {                    _builder.AppendLine( "<script type=‘text/javascript‘>" );                    _builder.AppendLine( "_setProgress(" + i * 4 + ");" );                    _builder.AppendLine( "</script>" );                }                this.Response.Write(_builder.ToString());                this.Response.Flush();            }        }    }}
效果預覽:

參考:http://www.cnblogs.com/isun/p/4178942.html

使用 Asp.Net Response.Write() 製作即時進度條

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.