⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 16.8.txt

📁 《Microsoft Visual C# .NET 2003开发技巧大全》源代码
💻 TXT
字号:
Listing 16.8 Persisting Data with the Application Object
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace _12_ApplicationState
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox tbTranscript;
protected System.Web.UI.WebControls.TextBox tbMessage;
protected System.Web.UI.WebControls.Button btnSend;
private void Page_Load(object sender, System.EventArgs e)
{
RefreshTranscript();
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
public void RefreshTranscript()
{
int msgID = 0;
string transcript = “”;
// enumerate through application collection
while( Application[msgID.ToString()] != null )
{
transcript += Application[msgID.ToString()].ToString()+”\r\n”;
msgID++;
}
tbTranscript.Text = transcript;
}
private void btnSend_Click(object sender, System.EventArgs e)
{
int lastMsgID;
if( Application[“lastMsgID”] == null )
{
lastMsgID = 0;
}
else
{
lastMsgID = Int32.Parse(
Application[“lastMsgID”].ToString() ) + 1;
}
// save data in application collection
Application[lastMsgID.ToString()] = Session.SessionID.ToString() +
“: “ + tbMessage.Text;
Application[“lastMsgID”] = lastMsgID.ToString();
RefreshTranscript();
}
}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -