Category Archives: Chat Application

How to Create Chat Application in ASP.Net with C#

– In this post we are going to learn, create simple chat in asp.net using C# language.

STEP 1 – First Create asp.net web application and Create Three web form named Home.aspx, Chatting.aspx and Msg.aspx.

STEP 2 – Design Home.aspx form like below :

Here is the HTML code for Home.aspx

<body>
<form id=”form1″ runat=”server”>
<div>
<table style=”z-index: 100; left: 344px; position: absolute; top: 160px”>
<tr>
<td colspan=”3″ style=”text-align: center”>
<strong><span style=”font-size: 16pt; color: #0000cc”>Chat Application Login Area</span></strong>
<br />
<br />
</td>
</tr>
<tr>
<td style=”width: 100px; text-align: right;”>
<strong>
Name : </strong>
</td>
<td style=”width: 100px”>
<asp:TextBox ID=”txtname” runat=”server”></asp:TextBox></td>
<td style=”width: 100px”>
</td>
</tr>
<tr>
<td style=”width: 100px”>
</td>
<td style=”width: 100px”>
<asp:Button ID=”btnlogin” runat=”server” OnClick=”btnlogin_Click” Text=”Login” /></td>
<td style=”width: 100px”>
</td>
</tr>
</table>

</div>
</form>
</body>

The Output of Home.aspx

Create chat appication in ASP.NET with C#

Create chat appication in ASP.NET with C#

STEP 3 – Now, Design Msg.aspx page like :

<html xmlns=”http://www.w3.org/1999/xhtml” >
<head runat=”server”>
<title>Chat Message</title>
<meta http-equiv=”REFRESH” content=”2″>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:TextBox ID=”txtmsg” runat=”server” Height=”290px” ReadOnly=”True” TextMode=”MultiLine”
Width=”490px”></asp:TextBox></div>
</form>
</body>
</html>

STEP 4 – Write Below code in Msg.aspx.cs file at Page_Load Event

protected void Page_Load(object sender, EventArgs e)
{
string msg = (string)Application[“msg”];
txtmsg.Text = msg;
}

STEP 5 – Now, Design Chatting.aspx Page :

<body>
<form id=”form1″ runat=”server”>
<div>
<table style=”z-index: 100; left: 96px; position: absolute; top: 16px”>
<tr>
<td style=”height: 39px; text-align: center;” colspan=”2″>
<asp:Label ID=”lblwelcome” runat=”server” Font-Bold=”True” ForeColor=”Purple”></asp:Label><br />
<strong><span style=”font-size: 20pt; color: #0033cc”>Simple Chat Application in ASP.Net
C#</span></strong></td>
</tr>
<tr>
<td colspan=”2″ style=”height: 39px”>
<iframe frameborder=”no” height=”315″ scrolling=”no” src=”MSG.aspx” width=”515″>
</iframe>
</td>
</tr>
<tr>
<td colspan=”2″ style=”text-align: center”>
<table>
<tr>
<td style=”width: 100px”>
<asp:TextBox ID=”txtsend” runat=”server” Height=”50px”
TextMode=”MultiLine” Width=”384px”></asp:TextBox></td>
<td style=”width: 100px”>
<asp:Button ID=”btnsend” runat=”server” OnClick=”btnsend_Click” Text=”SEND” BackColor=”CornflowerBlue” Font-Bold=”True” Font-Size=”X-Large” ForeColor=”Black” Height=”56px” Width=”104px” /></td>
</tr>
</table>
</td>
</tr>
<tr>
<td style=”width: 100px”>
</td>
<td style=”width: 100px”>
</td>
</tr>
</table>

</div>
</form>
</body>

– The Out Put of Chatting .aspx is like :

Create simple chat in asp.net with C#

Create simple chat in asp.net with C#

STEP 6 – Write Below code at Page_load Event of Chatting.aspx Page.

protected void Page_Load(object sender, EventArgs e)
{
lblwelcome.Text = “Welcome ” + Session[“name”].ToString();
}

And the Last write Below code at BtnSend Msg Click Event of Chatting.asp.cs page.

protected void btnsend_Click(object sender, EventArgs e)
{
if (txtsend.Text != “”)
{
string name = Session[“name”].ToString();
string message = txtsend.Text;
txtsend.Text = “”;
string my = name + “::” + message;

Application[“msg”] = Application[“msg”] + my + Environment.NewLine;
txtsend.Text = “”;
}
}

– After doing this things, you will enjoy online chat application in ASP.Net with C#.

 

Create Simple Chat Application in ASP.Net with C#

Simple Chat Application in ASP.Net

Develop Simple chat application in ASP.Net is easy task for who they know about the Application object.

STEP 1 – Open the Visual Studio and create new website in ASP.Net with C# Language.

STEP 2 – Here we have only one Default.aspx page, Now Add new web form chat.aspx and msg.aspx.
STEP 3 – Design the chat.aspx form like below:

– Here is HTML code for chat.aspx form.

<body>
<form id=”form1″ runat=”server”>
<div>
<table>
<tr>
<td colspan=”2″>
<asp:Image ID=”Image1″ runat=”server” ImageUrl=”~/meera.png” /></td>
</tr>
<tr>
<td style=”width: 100px; text-align: right”>
</td>
<td style=”width: 94px; text-align: center”>
<strong><span style=”font-size: 20px; color: #0000cc”>Simple Chat Application in ASP.Net&nbsp;&nbsp;
</span></strong></td>
</tr>
<tr>
<td style=”width: 100px; text-align: right”>
<strong>UserName</strong>:</td>
<td style=”width: 94px”>
<asp:TextBox ID=”txtname” runat=”server”></asp:TextBox>
<asp:Button ID=”brnadd” runat=”server” OnClick=”brnadd_Click” Text=”ADD” Font-Bold=”True” />
<asp:Label ID=”lbluname” runat=”server” Font-Bold=”True” ForeColor=”#004000″></asp:Label></td>
</tr>
<tr>
<td style=”width: 100px; height: 260px”>
</td>
<td style=”width: 94px; height: 260px”>
<%–<asp:TextBox ID=”txtmsg” runat=”server” Height=”250px” TextMode=”MultiLine” Width=”472px”></asp:TextBox>–%>
<iframe frameborder=”no” height=”315″ scrolling=”no” src=”MSGG.aspx” width=”515″>
</iframe>

</td>
</tr>
<tr>
<td style=”width: 100px; height: 77px;”>
</td>
<td style=”width: 94px; height: 77px;”>
<table style=”width: 480px”>
<tr>
<td style=”width: 100px; height: 50px;”>
<asp:TextBox ID=”txtsend” runat=”server” Height=”40px” TextMode=”MultiLine” Width=”384px”></asp:TextBox></td>
<td style=”width: 100px; height: 50px;”>
<asp:Button ID=”Button1″ runat=”server” Height=”47px” OnClick=”Button1_Click” Text=”SEND”
Width=”72px” Font-Bold=”True” /></td>
</tr>
</table>
</td>
</tr>
</table>

</div>
</form>
</body>

– The Out put of chat.aspx is like :

Simple Chat Application in ASP.Net

Simple Chat Application in ASP.Net

STEP 4 – Now design the msg.aspx form like :

– Here is HTML code for msg.aspx.

<head runat=”server”>
<title>Untitled Page</title>
<meta http-equiv=”REFRESH” content=”2″>
</head>
<body>
<form id=”form1″ runat=”server”>
<div>
<asp:TextBox ID=”txtmsg” runat=”server” Height=”290px” ReadOnly=”True” TextMode=”MultiLine”
Width=”490px”></asp:TextBox></div>
</form>
</body>

 

STEP 6 – Now write below code in page_lode of msg.aspx

 protected void Page_Load(object sender, EventArgs e)
{

string msg = (string)Application[“message”];
txtmsg.Text = msg;
}

STEP 7 – write below code on btnAdd Click Event in chat.aspx.cs page.

protected void brnadd_Click(object sender, EventArgs e)
{
Session[“name”] = txtname.Text;
lbluname.Text = “Welcome ” + txtname.Text;
txtname.Text = “”;

}

 

STEP 8 – write below code on btnsend Click Event in chat.aspx.cs page.

 protected void btnsend_Click(object sender, EventArgs e)
{
string name = Session[“name”].ToString();
string message = txtsend.Text;
string my = name + “::” + message;

Application[“message”] = Application[“message”] + my + Environment.NewLine;
txtsend.Text = “”;
}

– The Out put of chat application is :

Simple Chat Application in ASP.Net

Simple Chat Application in ASP.Net

Simple Chat Application in ASP.Net C#.

Simple Chat Application in ASP.Net

Simple Chat Application in ASP.Net

After doing this much you will enjoy free simple chat application……