Download Source Files - 18.8 KB
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 Know, you won 'T Be Able To Use 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 IOWN.
USING THE CODE
Replace this class if you are for a database to save the message:
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 Sdealr)
{
String SRESPONSE = ""
For (int i = 0; i { SRESPONSE = SRESPONSE FormatChat (Parray [i] .tostring (), sdealer; } Return (SRESPONSE); } Static Private String Formatchat (String Sline, String Sdealer) { INT IFIRST = Sline.indexof ("~"); 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 chat page is pretty Simple; this is the code behind asp.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 ["" "" = "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. // InitializationComponent (); Base.onit (E); } /// /// Required Method for Designer Support - Do Not Modify /// The contents of this method with the code editor. /// summary> Private vidinitiRizeComponent () { this.bt_send.click = New system.eventhandler (this.bt_send_click); This.Load = New System.EventHandler (this.page_load); } #ndregion 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 = "" } } } ........... .. ........................ Points of interest THE MAGIC? NONE, A Simple Request of the Second Page Into The