Creating a Simple Chat application in .Net
Chat applications are found in almost all the sites that are interactive with the users. Chat rooms in the websites provide a means of communicating with the customer service cell of any company so that the customer gets the first hand information on any products and services that is on display in the site.
Chat applications with many features are even sold for a sum but some sites may require a very simple feature to interact with the customer service personnel who is online. Such simple chat applications can be built on your own. Let us see some algorithm and the code snippets that go in the way of creating a simple chat application.
To store the messages that are typed during a chat you can either use static arrays or use a database for that purpose. Using a database is a good way of storing messages. However you can also use static arrays for that purpose. The chat application that we are going to see will work on any browser that supports <iFrame>, since we are using <iFrame> to display the chat window of the application. We will be refreshing the page in the <iFrame> to refresh the chat window alone without refreshing the whole page in which the <iFrame> is present.
To enter the chat you need an .aspx page where the user enters the name of the room and the user id. Then the user presses a Join chat button. You can pass these parameters to the ChatPage.aspx where you will be having an iFrame for displaying the messages and a text box control to type the messages and a button to send the typed messages. To pass the parameters collected from the user to the ChatPage.aspx you can use the following code which looks like,
Join_Click(object sender, System.EventArgs e)
A code snippet for adding messages can be something like given below.
ArrayList stArray = new ArrayList();
if ( stArray.Count
> 100 )
Within the ChatPage.aspx, once you type the message that is to be sent and when you click the Send button, you need to add the message that is typed. You check the text box for that purpose and if it contains any text you just add the message to the static array.
Send_Click(object sender, System.EventArgs e)
if ( Request.Params["Room"]
!= null )
if ( Request.Params["User"]
!= null )
You can use the following code to refresh the page in the <iFrame> to display all the messages that are typed.
Response.Write( "<meta http-equiv=\"Refresh\"content=\"4\">" );
Call the method that is created to display all the messages in the <iFrame> after refreshing the page.
You can thus create a simple chat application which can be used in all the sites that need interaction with the user.
to our mailing list and receive new articles Note
: We never rent, trade, or sell my email lists to Visit
.NET Programming Tutorial Homepage ______________________________________________________
to our mailing list and receive new articles
: We never rent, trade, or sell my email lists to
Visit .NET Programming Tutorial Homepage