建立 Default9.aspx 頁面
使用 SriptManager 和 UpdataPanel 在 UpdataPanel 放一個 、 timer 實現 、 使用兩個 Viewstate, ViewState[“index”]儲存下標和ViewState[“content”] 列印的內容、、、
代碼 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
public partial class Default6 : System.Web.UI.Page
{
public int index {
get { return (int)ViewState["index"]; }
set { ViewState["index"] = value; }
}
public String content
{
get { return (String)ViewState["content"]; }
set { ViewState["content"] = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
content = "你們好,我是你爺爺、、、、";
index = 0;
Timer1.Enabled = true;
}
}
protected void Timer1_Tick(object sender, EventArgs e)
{
this.Label1.Text+=content[index].ToString();
index++;
if (index >=content.Length) {
Timer1.Enabled = false;
}
}
}
頁面:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default9.aspx.cs" Inherits="Default9" %>
<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>