gpt4 book ai didi

jquery - Facebook 风格的 ASP.NET 聊天组件

转载 作者:行者123 更新时间:2023-11-30 05:25:05 26 4
gpt4 key购买 nike

我将推出一个有点像社交媒体网站的网站。我需要一个必须基于 AJAX 的 ASP.NET 聊天控件,拥有 jQuery 会很好,因为我的整个网站将使用 jQuery Themes 进行主题化.我正在寻找类似于 Gmail 或 facebook 风格的聊天工具,因为从用户的角度来看,它非常易于使用,并且不会占用太多屏幕空间。

这里没有我能找到的任何想法。我已经在谷歌上找遍了,但没能为 ASP.NET 找到类似的东西。我看到有很多 Php。以前有人做过这个吗?我们想在 6 月推出该网站,所以我必须快速找到一些东西。感谢您的帮助。

最佳答案

试试这个..示例图像 - SimpleChat.jpg简介

为什么不呢,如何为您的网站创建一个简单的聊天室?嗯,最好的方法是使用一个好的数据库来存储消息;但是,出于演示目的,我将使用静态数组。我知道,您将无法在您的网络场中使用它。以本文作为概念,而不是作为解决方案。这个简单的网络聊天程序适用于任何支持 .

的浏览器。

此外,您还可以选择多个聊天室。为什么不从那里扩展到更多的 channel 。背景

几个月前,我一直在寻找一个完整的在线客服 ASP.NET 控件来让我的生活更轻松,但没有找到任何有趣的东西,所以我构建了自己的。使用代码

如果您使用数据库保存消息,请替换此类:折叠

public class Chat
{
static protected ArrayList pArray = new ArrayList();


static public void AddMessage(string sDealer,
string sUser, string sMsg)
{
string sAddText = sDealer + "~" + sUser + "~" + sMsg;
pArray.Add(sAddText);

if ( pArray.Count > 200 )
{
pArray.RemoveRange(0,10);
}
}

static public string GetAllMessages(string sDealer)
{
string sResponse = "";

for (int i=0; i< pArray.Count; i++)
{
sResponse = sResponse +
FormatChat(pArray[i].ToString(), sDealer);
}

return(sResponse);
}

static private string FormatChat(string sLine, string sDealer)
{
int iFirst = sLine.IndexOf("~");
int iLast = sLine.LastIndexOf("~");

string sDeal = sLine.Substring(0, iFirst);
if ( sDeal != sDealer)
return("");

string sUser = sLine.Substring(iFirst+1, iLast-(iFirst+1));

string sMsg = sLine.Substring(iLast+1);

string sRet = "" + sUser + ": " + sMsg + "";

return(sRet);
}
}

上面的代码像在数据库中一样从静态数组读取和写入。该代码只允许数组中有 200 条消息,之后它会删除前 10 条消息。

聊天页面非常简单;这是 aspx.cs 背后的代码:折叠

public class ChatWin : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TB_ToSend;
protected System.Web.UI.WebControls.Button BT_Send;

private void Page_Load(object sender, System.EventArgs e)
{
if ( Page.IsPostBack == false )
{
if ( Request.Params["Channel"] != null )
Session["ChatChannel"] =
Request.Params["Channel"].ToString();
else
Session["ChatChannel"] = "1";

}
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();
base.OnInit(e);
}

/// <SUMMARY>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </SUMMARY>

private void InitializeComponent()
{
this.BT_Send.Click +=
new System.EventHandler(this.BT_Send_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

public string GetChatPage()
{
return("TheChatScreenWin.aspx");
}

private void BT_Send_Click(object sender, System.EventArgs e)
{
string sChannel = "";
string sUser = "";

if ( Request.Params["Channel"] != null )
sChannel = Request.Params["Channel"].ToString();
else
sChannel = "1";

if ( Request.Params["User"] != null )
sUser = Request.Params["User"].ToString();
else
{
Random pRan = new Random();
int iNum = pRan.Next(9);
sUser = "Annonymouse" + iNum;
}


if ( TB_ToSend.Text.Length > 0)
{
PageModule.Chat.AddMessage(sChannel,
sUser,
TB_ToSend.Text);

TB_ToSend.Text = "";
}
}
}

单击“发送”按钮时,它会调用函数 AddMessage 将一行添加到静态数组的末尾。

标签内的页面每 4 秒刷新一次,而不刷新您的实际页面。

关于jquery - Facebook 风格的 ASP.NET 聊天组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5882696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com