谁有ajax做的web聊天室的源码啊?

shelly 2012-05-10 04:40:14
初学asp.net里的C#开发网站,老师要求写一个网页版的聊天室,能实现即时通信,那位大神能慷慨贡献一些聊天室的源码啊?
...全文
140 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
指间的风 2012-05-14
  • 打赏
  • 举报
回复
保存聊天记录,
那需要设计一个可以保存数据的方式,
数据库,文件。都可以,然后设计一下,数据结构

比如用户表,需要登录后发言,然后记录聊天记录。
我上边的代码,只是一个简单的ajax的聊天室。
指间的风 2012-05-14
  • 打赏
  • 举报
回复
多对多,你可以打开几个不同浏览器,测试一下效果。
shelly 2012-05-11
  • 打赏
  • 举报
回复
这样写确实是简单,可是聊天记录却没有保存下来。如果我多对多的进行聊天呢?
shelly 2012-05-11
  • 打赏
  • 举报
回复
虽然简洁但也能说明一些问题,谢谢!!!
指间的风 2012-05-10
  • 打赏
  • 举报
回复
<asp:Timer ID="timer" Interval="5000" runat="server" OnTick="timer_Tick">

这里的 5000 代表 5秒 ajax 刷新一下 页面
指间的风 2012-05-10
  • 打赏
  • 举报
回复
前台


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!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:Timer ID="timer" Interval="5000" runat="server" OnTick="timer_Tick">
</asp:Timer>
<asp:Label ID="Label2" runat="server" Text="用户名"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="内容"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>

<asp:Button ID="Button1" runat="server" Text="输入" onclick="Button1_Click" />
<br/>
<br/>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>




后台


using System;

namespace WebApplication1
{
public partial class WebForm1 : System.Web.UI.Page
{
private static string messagelist;
protected void Page_Load(object sender, EventArgs e)
{

}

protected void timer_Tick(object sender, EventArgs e)
{
Label1.Text = messagelist;
}

protected void Button1_Click(object sender, EventArgs e)
{
messagelist = TextBox2.Text +" : " +TextBox1.Text +"</br>" + messagelist;
Label1.Text = messagelist;
}
}
}


指间的风 2012-05-10
  • 打赏
  • 举报
回复
用 vs 2010 建立一个 asp.net 程序

然后使用自带的AJAX Extensions控件即可完成。

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧