新水浒q传阵营任务奖励:如何建一个聊天室
来源:百度文库 编辑:查人人中国名人网 时间:2024/05/04 19:01:20
一个入门级的在线聊天室代码
Asp.Net (C#语言)
一个入门级的在线聊天室代码
--------------------------------------------------------------------------------
这是前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="chating.aspx.cs" Inherits="chating" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!2005年胭脂鱼制作 badnewfish@yahoo.com.cn >
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<meta http-equiv="refresh" content="10*1000"><!定义自动刷新时间为10秒“九度IT技术社区”指导>
</head>
<body>
<form id="form1" runat="server">
<div>
胭脂鱼聊天室<br />
<asp:TextBox ID="txtchatbox" runat="server" Height="200px" ReadOnly="True" TextMode="MultiLine"
Width="500px"></asp:TextBox><br />
<table>
<tr>
<td style="width: 210px; height: 21px">
请输入您的名称:</td>
<td style="width: 236px; height: 21px">
<asp:TextBox ID="txtname" runat="server" Width="114px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 210px">
请输入您的发言:</td>
<td style="width: 236px">
<asp:TextBox ID="txtmessage" runat="server" MaxLength="100" Width="420px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 210px">
<asp:Button ID="btnpost" runat="server" OnClick="btnpost_Click" Text="发言" /></td>
<td style="width: 236px">
<asp:Button ID="btnclearlog" runat="server" OnClick="btnclearlog_Click" Text="清除" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
这是后台代码:
//参考书籍《asp.net入门经典》
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
public partial class chating : System.Web.UI.Page
{
//页面加载聊天细节时的代码
protected void Page_Load(object sender, EventArgs e)
{
txtchatbox.Text = (string)Application["ChatLog"];
}
//当单击“留言”按扭时的代码 在Application 对象中保存传递信息的人名和信息本身
protected void btnpost_Click(object sender, EventArgs e)
{
string tad = "\t";
string newline = "\r";
string newmessage = txtname.Text + ":" + tad + txtmessage.Text + newline
+ Application["ChatLog"];
if (newmessage.Length > 500)
{
newmessage = newmessage.Substring(0, 499);
}
Application["ChatLog"] = newmessage;
txtchatbox.Text = (string)Application["ChatLog"];
}
//点击“清除”按扭时的代码
protected void btnclearlog_Click(object sender, EventArgs e)
{
Application["ChatLog"] = "";
txtchatbox.Text = (string)Application["ChatLog"];
}
}
请问你也是想做了放在网站上的吗?我现在也正在策划一个网站呢。我们交流一下吧。加我QQ,985543。我男朋友是做网站的,希望我们可以互相帮忙。
在百度上搜索聊天的原代码,放到服务器上就行了啊!