talk.aspx.cs

来自「一个简单的JSP聊天室源码 实现无刷新聊天功能 内容为无刷新聊天室原理」· CS 代码 · 共 48 行

CS
48
字号
/*
 * 对在asp.net2.0下利用ajax实现无刷新网页聊天技术原理的探索
 * 作者:Gary
 * 本小聊天室纯属自娱自乐
 * 仅仅是完成了聊天室的基本原理的探索
 * 没有注重资源的调解和功能的完善
 * http://edidu.cnblogs.com
 * 技术支持:asp.net2.0 + Ajax
 * 关键字:asp.net2.0  ajax  timer  updatepanel  application  session
-*/
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Management;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //Application["TalkContent"] = "Hello Gary!";
        Label1.Text = Application["TalkContent"].ToString ();
        //Application["TalkContent"] = "";
        Page.Title = "Hello " + Session["Name"].ToString ()+" WelCome to Talkroom!";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text == "")
            return;
        Application["TalkContent"] += Session["Name"] +" Say: "+ TextBox1.Text + "<br>";
        Label1.Text = Application["TalkContent"].ToString ();
        TextBox1.Text = string.Empty;
    }
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        Label1.Text = Application["TalkContent"].ToString();
        //
        // 到一定的限度,清屏
        //
        if (Application["TalkContent"].ToString().Length > 2000)
            Application["TalkContent"] = "";
    }
}

⌨️ 快捷键说明

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