温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:我的Asp.net三层聊天室源码
当前文件:
MyChatRoom/Speak.aspx.cs,打开代码结构图
MyChatRoom/Speak.aspx.cs,打开代码结构图
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;
using MyChatRoom.BusinessLogicLayer;
//该源码下载自www.51aspx.com(51aspx.com)
namespace MyChatRoom.WebLayer
{
/// <summary>
/// Speak 的摘要说明。
/// </summary>
public partial class Speak : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
/// <summary>
/// 用户单击“发言”时的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ButtonSpeak_Click(object sender, System.EventArgs e)
{
//获取用户输入的发言信息
string userName=Session["user_name"].ToString(); //用户名
string createTime=System.DateTime.Now.ToLongTimeString();//发言时间
string content=TextBoxContent.Text; //发言内容
string color=DropDownListColor.SelectedItem.Value; //颜色
string emotion=DropDownListEmotion.SelectedItem.Value; //表情
Message message=new Message(); //实例化Message类
message.Add(userName,createTime,content,color,emotion); //利用Message类的Add方法,向数据库添加留言
//清空发言框
TextBoxContent.Text="";
}
/// <summary>
/// 用户单击“离开”时的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ButtonExit_Click(object sender, System.EventArgs e)
{
Session["user_name"]=null; //销毁Session中的用户信息
Response.Write("<Script Language=JavaScript>window.top.location=\"Login.aspx\";</Script>");
}
}
}

