Click here to Skip to main content
15,352,974 members
Articles / Web Development / HTML
Posted 15 Mar 2006


59 bookmarked

A Sample Chat Application using Mike Schwarz's AJAX Library

Rate me:
Please Sign up or sign in to vote.
4.14/5 (17 votes)
15 Mar 20061 min read
An article on developing a chat application using AJAX and .NET.

Sample Image


This article describes a sample chat application using Mike Schwarz's AJAX library. With the development of AJAX as a new development mode for the Web, every one seems to be more interested in it. Here, I have used an AJAX library for .NET developed by Mike Schwarz. This library is basically an HTTP handler which redirects AJAX requests from a client to the appropriate types. This library in turn uses JSON - JavaScript Object Notation which is a data-interchange format; using JSON, we can access even complex types on the client side.

Using the code

To use Schwarz's AJAX library, we have to register the type which we want to associate for AJAX calls:

// Register

Add an HTTP handler section to web.config:

    <add verb="POST,GET" path="ajax/*.ashx" 
         type="Ajax.PageHandlerFactory, Ajax" />

You can find further details in the library documentation. Now, to start out with the code: the application mainly consists of two files, Chat.aspx and DragAndPost.js. The DragAndPost.js consists of a function which posts the AJAX request and gets a hashtable back and populates the open chat rooms.

You will have a context menu to open private chat rooms to which you can use the same context to invite as well. The source code is pretty simple, all we need to do is configure a lot of things in JavaScript, like opening divs on double click etc. Post your comments, so that I can improve it.

This function creates a div on the double click of a chat room:

function CreateDiv(DivID,Roomid)
    var Divelement=document.createElement("DIV");
//The Drag part of Div is handled By
function movemouse(e)
  if (isdrag)
  { = nn6 ? tx + e.clientX - x : 
                            tx + event.clientX - x;  = nn6 ? ty + e.clientY - y : 
                            ty + event.clientY - y;
    return false;
function selectmouse(e) 
  fobj = nn6 ? : event.srcElement;
  if (fobj.parentElement.tagName!="DIV" 
                 && fobj.tagName=="DIV")
        isdrag = true;
        tx = parseInt(;
        ty = parseInt(;
        x = nn6 ? e.clientX : event.clientX;
        y = nn6 ? e.clientY : event.clientY;
        return false;
document.onmouseup=new Function("isdrag=false");

I have used a string builder like class to speed up the client side string manipulation:

function StringBuffer() { 
  this.buffer = [];

StringBuffer.prototype.append = 
  function append(string) { 
    return this; 

StringBuffer.prototype.toString = 
  function toString() { 
    return this.buffer.join(""); 


  • Posted on March 07, 2006.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
India India
i had been programming in .NET for 2 years,
Visit me at my Space

Comments and Discussions

Generalnice but needs some enhancement Pin
qusai8422-Apr-11 2:24
Memberqusai8422-Apr-11 2:24 
GeneralMy vote of 4 Pin
qusai8422-Apr-11 2:22
Memberqusai8422-Apr-11 2:22 
QuestionHow to save the chat information Pin
Nag242519-Aug-09 18:33
MemberNag242519-Aug-09 18:33 
GeneralDatabase for this project Pin
mharoon bhatti11-Dec-08 20:40
Membermharoon bhatti11-Dec-08 20:40 
GeneralGood! Pin
JasonC7213-Oct-08 5:26
MemberJasonC7213-Oct-08 5:26 
QuestionChat messenger allows 1-to-1 communication [modified] Pin
Mr. Saikat Choudhury7-Apr-08 21:38
MemberMr. Saikat Choudhury7-Apr-08 21:38 
GeneralExcelent sample!! [modified] Pin
zSegundo29-Aug-07 8:10
MemberzSegundo29-Aug-07 8:10 
Generalhelp needed Pin
vimala soujanya21-Jun-07 20:58
Membervimala soujanya21-Jun-07 20:58 
GeneralRe: help needed Pin
arindam.roy26-Oct-07 23:52
Memberarindam.roy26-Oct-07 23:52 
Questionhow to display text as it is send Pin
lata kumari10-Jun-07 20:18
Memberlata kumari10-Jun-07 20:18 
GeneralNice Pin
Member 35781938-Mar-07 19:30
MemberMember 35781938-Mar-07 19:30 
QuestionQuery Pin
vcksaran21-Sep-06 23:04
Membervcksaran21-Sep-06 23:04 
Questionuser status Pin
jasine7-Aug-06 23:41
Memberjasine7-Aug-06 23:41 
Generalsimple and effictive Pin
Ramesh Ramalingam5-Aug-06 1:00
MemberRamesh Ramalingam5-Aug-06 1:00 
GeneralAjax enabled DataGrid - Chat Application Example Pin
OmegaCD26-May-06 2:59
MemberOmegaCD26-May-06 2:59 
GeneralCool Pin
-JeRoK-12-May-06 9:53
Member-JeRoK-12-May-06 9:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.