Hi thsi is simple Messanger application in asp.net.
for this u need to create two derault.aspx and default2.aspx two pages and one global.aspx file.
u can add some more feature but it is very simple use of application variable.
Dfault.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
Hashtable schedule = new Hashtable();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string[] data = (string[])Application["msg"];
int i = 0;
for (i = data.Length - 1; i > 0; i--)
{
if (data[i] == "")
break;
data[i] = data[i - 1];
}
data[i] = "<strong> Welcome " + TextBox1.Text + " :</strong> ";
Session["name"] = "<strong> "+
TextBox1.Text + "</strong> ";
Server.Transfer("Default2.aspx");
}
}
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title> Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" Style="z-index: 103; left: 398px; position: absolute;
top: 152px"> </asp:TextBox>
<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="#00C000" Style="z-index: 105;
left: 273px; position: absolute; top: 155px" Text=" Nick Name"> </asp:Label>
<asp:Button ID="Button1" runat="server" Style="z-index: 101;
left: 455px; position: absolute; top: 193px" Text="enter" OnClick="Button1_Click" />
</div>
</form>
</body>
</html>
Global.aspx
<%@ Application Language="C#" %>
<script runat="server">
void Application_Start(object sender, EventArgs e)
{
Application["msg"]= new string[20];
}
void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown
}
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
void Session_Start(object sender, EventArgs e)
{
string name = "";
}
void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.
}
</script>
Default2.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Xsl;
using System.Xml.XPath;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string[] data = (string[])Application["msg"];
for (int i = 0; i <data.Length; i++)
Response.Write(data[i]+"<br> ");
Response.AppendHeader("Refresh", "60; URL=http://localhost:3106/TestAsp/Default2.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
string[] data = (string[])Application["msg"];
int i = 0;
for ( i= data.Length - 1; i > 0; i--)
{
if (data[i] == "")
break;
data[i] = data[i - 1];
}
data[i] = (string)Session["name"] + TextBox1.Text;
Application["msg"] = data;
}
}
Default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title> Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="z-index: 100;
left: 147px; position: absolute; top: 522px" Text="Submit" />
<asp:TextBox ID="TextBox1" runat="server" Style="z-index: 101; left: 133px; position: absolute;
top: 483px" OnTextChanged="TextBox1_TextChanged" Width="362px"> </asp:TextBox>
<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="#00C000" Style="z-index: 103;
left: 21px; position: absolute; top: 487px" Text="Write Message" Width="102px"> </asp:Label>
</div>
</form>
</body>
</html>
See
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment