Facebook 风格的 ASP.NET 聊天组件

发布于 2024-11-04 17:06:12 字数 280 浏览 3 评论 0原文

我将启动一个有点像社交媒体网站的网站。我需要一个基于 AJAX 的 ASP.NET 聊天控件,如果有 jQuery,那就太好了,因为我的整个网站将使用 jQuery 主题进行主题化。我正在寻找类似于 Gmail 或 Facebook 风格的聊天功能,因为从用户的角度来看,它非常易于使用,并且不会占用大量屏幕空间。

这里没有我能找到的任何想法。我查遍了 google,但没有找到 ASP.NET 的类似内容。我看到有很多 PHP 的。以前有人从事过这方面的工作吗?我们想在六月推出该网站,所以我必须快速找到一些东西。感谢您的帮助。

I will be launching a site that is somewhat like a social media site.I need a ASP.NET chat control which has to be AJAX based and it will be nice to have jQuery as my entire site will be themed using jQuery Themes. What i am looking for is something similar to the Gmail or facebook style chat as that is very easy to use from the users point of view and does not take a lot of screen real estate.

Any thoughts here no what i can find. I have looked all over google and have not been able to find anything like that for ASP.NET. There are many out there for Php that i see. Has anyone worked on this before? We want to launch the site in June so i have to find something quick. Appreciate the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[浮城] 2024-11-11 17:06:12

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

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

此外,您还可以选择多个聊天室。为什么不从那里开始,从一个渠道扩展到另一个渠道呢?
背景

几个月前,我一直在寻找一个完整的在线客户服务 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 背后的代码:
单击 SEND 按钮时,它会调用函数

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 秒刷新一次,而不刷新您的实际页面。

try this..
Sample Image - SimpleChat.jpg
Introduction

And why not, how to create an easy chat room for your web site? Well, the best way is to use a nice database to store messages; however, for demo purposes, I'll use a static array. I know, you won't be able to use it in your web farm. Take this article as the concept, not as a solution. This simple web chat program is intended to work in any browser supporting .

Also, you can select multiple chat rooms. Why not extend from there and more from channel to channel.
Background

Some months ago, I was looking for a complete on-line customer service ASP.NET control to make my life easier, did not find anything interesting, so I built my own.
Using the code

Replace this class if you are using a database to save the messages:
Collapse

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);
    }
}

The above code reads and writes from the static array like in a database. The code only allows having 200 messages in the array, after that it deletes the top 10 at the time.

The Chat page is pretty simple; this is the code behind aspx.cs:
Collapse

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 = "";        
        }
    }
}

When the SEND button is clicked, it calls the function AddMessage that adds a row into the end of the static array.

The page inside the tag refreshes every 4 seconds without refreshing your actual page.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文