How to create a chat by using .NET
Step 1:
>Create a New empty Website
>Right click on Application Add new Item
> Select File Global Application class and name it as global.asax
> Write Below code in global.asax
Global.asax
// Application_Start( write code in)
Application.Lock();
Application["tusers"]=0; Note: tusers= Total Users
Application["ousers"]=0; ousers=Online users
Application["msgs"]="";
Application.Unlock();
// Session_Start(write code in)
int tusers,ousers;
Application.Lock();
tusers=(int)Application["tusers"]+1; // Unboxing
ousers=(int)Application["ousers"]+1;
Application["tusers"]=tusers;
Application["ousers']=ousers;
Application.Unlock();
// Session_End(write code in)
int ousers;
Application.Lock();
ousers=(int)Application["ousers"]-1;
Application["ousers"]=ousers;
Application.Unlock();
Step 2:
> Add a webform
>Name it as Default.aspx
Default.aspx [Design]
> Design like below diagram
> Use table (4 rows , 1 column)
(To see complete image click on it) |
// Page_Load (write code in)
Application.Lock();
lblTotalUsers.Text=Application["tusers"].Tostring();
lblOnlineUsers.Text=Application["ousers"].ToString();
lblMsg.Text=Application["msgs"].ToString();
Application.Unlock();
// Logout_buttonclick(write code in)
Session.Abandon();
// Send_buttonclick(write code in)
string uname,msg,msgs;
uname=txtName.Text;
if(uname.Lenght>0)
msg.string.Format("<font color =green> {0}:</font> {1}",uname,txtMsg.Text);
else
msg=string.Format("<font color =Red> Guest:</font> {0}",txtMsg.Text);
Application.Lock();
msgs=Application["msgs"].ToString() + "<br>" + msg;
Application["msgs"] = msgs;
Application.Unlock();
lblmsg.Text=msgs;
ALL THE BEST
0 comments:
Post a Comment