
March 31st, 2004, 10:19 PM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Simple Chat Page in ASP.NET using C#
I'm trying to implement a simple chat page on my site and it works except for I get duplicate
lines when I submit.
----Output--------
Jeff: test
Jeff: test
Jeff: message test
Jeff: message test
Code:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace StructuredSites
{
/// <summary>
/// Summary description for chat.
/// </summary>
public class chat : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtChatBox;
protected System.Web.UI.WebControls.TextBox txtMessage;
protected System.Web.UI.WebControls.Button btnPost;
protected System.Web.UI.WebControls.TextBox txtMyName;
protected System.Web.UI.WebControls.Button btnClearLog;
void Page_Load(object sender, System.EventArgs e)
{
txtChatBox.Text = "Welcome to SS Chat Online!";
}
public void btnClearLog_Click(object sender, EventArgs e)
{
Application["ChatLog"] = "";
txtChatBox.Text = (string)Application["ChatLog"];
}
public void btnPost_Click(object Sender, EventArgs e)
{
string tab = "\t";
string newline = "\r";
string messageLog = (string)Application["ChatLog"];
string newMessage = txtMyName.Text + ":" + txtMessage.Text + newline + messageLog;
if (newMessage.Length > 500)
{
newMessage = newMessage.Substring(0,499);
}
Application["ChatLog"] = newMessage;
txtChatBox.Text = (string)Application["ChatLog"];
}
#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.btnPost.Click += new System.EventHandler(this.btnPost_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
Anybody notice anything wrong here?
Thanks,
Jeff
Last edited by stumpy : April 1st, 2004 at 01:03 AM.
Reason: Please place code in [CODE] tags
|