.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 31st, 2004, 10:19 PM
mattisjd mattisjd is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 1 mattisjd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old April 12th, 2004, 01:25 PM
StudioReview StudioReview is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 30 StudioReview User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
Set a breakpoint and step through the code with the debugger. It should answer your question. When something behaves weird but you think your code is right, the debugger is the way to go!
__________________
Tivo Codes, Hacking the Tivo, and Adding a Second Drive to Your Tivo.
All this information at www.TivoSpy.com !

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > Simple Chat Page in ASP.NET using C#


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap