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……

One Response to Create Simple Chat Application in ASP.Net with C#

  1. Chandrakant says:

    Nice

Leave a Reply

Your email address will not be published. Required fields are marked *

6 + 8 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">