2011-05-04 30 views
5

我將推出一個有點像社交媒體網站的網站。我需要一個ASP.NET聊天控件,它必須基於AJAX,並且將jQuery作爲我的整個網站將主題使用jQuery主題。我正在尋找的東西類似於Gmail或Facebook風格的聊天,因爲從用戶的角度來看這很容易使用,並且不需要很多屏幕空間。Facebook風格的ASP.NET聊天組件

任何想法在這裏沒有我能找到。我已經看遍了所有的谷歌,並沒有能夠找到任何類似的ASP.NET。我看到有許多Php。有沒有人曾經在此之前?我們想在六月份推出這個網站,所以我必須快速找到一些東西。感謝幫助。

+0

在codeplex上搜索你會發現更多http://www.codeplex.com/site/search?query=chat&ac=3 – 2011-05-04 11:36:43

回答

3

試試這個.. 樣品圖片 - 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後面的代碼: 收起

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

當點擊了按鈕SEND時,它調用函數方法addMessage,增加了一行到靜態數組的末尾。

標記內的頁面每4秒刷新一次而不刷新實際頁面。