對(duì)于加載時(shí)間比較長(zhǎng)的ASP.NET頁(yè)面,我們可以在客戶(hù)端瀏覽器中顯示進(jìn)度條來(lái)顯示頁(yè)面正在裝載。下面就是具體的實(shí)現(xiàn)過(guò)程:
新建項(xiàng)目,名字為WebPortal,在項(xiàng)目類(lèi)型中選擇Visual C#項(xiàng)目或者Visual Basic項(xiàng)目都可;在模板類(lèi)型中選擇ASP.NET Web應(yīng)用程序;位置里輸入:http://localhost/WebPortal;添加新項(xiàng):名字為ShowPRogress的Web窗體。在您的Web窗體ShowProgress.aspx上添加任何其他的Web服務(wù)器控件。在ShowProgress.aspx上單擊右鍵,點(diǎn)“查看代碼”,在最上面輸入:Visual C# .NET代碼
using System.Threading;Visual Basic .NET代碼 Imports System.Threading在Page_Load事件里輸入: Visual C# .NET代碼 Response.Write("<div id='mydiv' >"); Response.Write("_"); Response.Write("</div>"); Response.Write("<script>mydiv.innerText = ';</script>"); Response.Write("<script language=javascript>;"); Response.Write("var dots = 0;var dotmax = 10;function ShowWait()"); Response.Write("{var output; output = '正在裝載頁(yè)面';dots++;if(dots>=dotmax)dots=1;"); Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText = output;}"); Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; "); Response.Write("window.setInterval('ShowWait()',1000);}"); Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';"); Response.Write("window.clearInterval();}"); Response.Write("StartShowWait();</script>"); Response.Flush(); Thread.Sleep(10000);Visual Basic .NET代碼 Response.Write("<div id='mydiv' >") Response.Write("_") Response.Write("</div>") Response.Write("<script>mydiv.innerText = ';</script>") Response.Write("<script language=Javascript>;") Response.Write("var dots = 0;var dotmax = 10;function ShowWait()") Response.Write("{var output; output = '正在裝載頁(yè)面';dots++;if(dots>=dotmax)dots=1;") Response.Write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innerText = output;}") Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible'; ") Response.Write("window.setInterval('ShowWait()',1000);}") Response.Write("function HideWait(){mydiv.style.visibility='hidden';") Response.Write("window.clearInterval();}") Response.Write("StartShowWait();</script>") Response.Flush() Thread.Sleep(10000)在ShowProgress.aspx窗體的html的中輸入: <script> HideWait(); </script>點(diǎn)在瀏覽器中查看即可
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注