.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Asp.net simple chat Application

Posted By:Dinkar       Posted Date: April 12, 2011    Points: 200    Category: ASP.NET    URL: http://www.dotnetspark.com  

Today we see chat Aplication using Asp.net its very simple but useful for our Application. Friends all of know Global.asax file in Asp.net if you don't know read first this as follow
 

Simple Chat Application in Asp.net:
Today we see chat Aplication using Asp.net its very simple but useful for our Application.
Friends all of know Global.asax file in Asp.net if you don't know read first this  as follow
Global.asax:

discuss the various events in Global.asax file.

Global Application Class [Global.asax]


Application state only achieved by adding Global.asax file into our project, it not mandatory to define Global.asax file web project, if you have not added Global.asax file, ASP.NET Runtime detects that there was no Application Statemangement in the current project.


 Events in Global.asax File


Some of the Events in Global.asax file are depicted as follows; this is not a complete list of events.


 
Application_Start: This event fires executes when the application starts running

 Application_End:
 This event ocurs on application shutdown

 Application_Error:
 This event ocurs when unhandled error occurs

 Session_Start:
 This event ocurs when new session is started.

 Session_End:
 This event occurs when session ends
  

So now we see step for chat Application:

Step 1) Open VS studio 2008/10


Step 2)Add wweb  two web form Default.aspx and Chating.aspx ok


Step 3) Now Right click on project and Add New Item in that select Global.asax file and  write follow


{

<%@ Application Language="C#" %>
 

<script runat="server">

  void Application_Start(object sender, EventArgs e)
  {
  // Code that runs on application startup
  Application.Lock();
  Application["msg"]="";
  Application.UnLock();

  }
 
  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)
  {
  // Code that runs when a new session is started

  }

  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>
 

}
 
Step 4)Now go Default.aspx page source code and write as follow


{

<form id="form1" runat="server">
  <script language="jscript" type="text/javascript">
  function popup()
  {
  var a=window.open("chating.aspx",'width=250,height=500,left=350,top=120')
  }
  script>
  <body onload="popup(); return false;">
}

Step 5)Now Design Chating .aspx page alongwith three textbox and One Button .


Step 6)Now go Chating.aspx page_load event and wrte code as follow


{

//Assigning Application Object to string Varaiable by Parsing
 

string msg = (string)Application["msg"];
  TextBox1.Text = msg;
}
 

Step 7) Now go to Chating .aspx Button double click event and write code as follow

{

string name = TextBox2.Text;
  string message = TextBox3.Text;
  string my = name + "::" + message;

  Application["msg"] = Application["msg"] + my + Environment.NewLine;

  TextBox1.Text = Application["msg"].ToString();

  TextBox3.Text = "";
}
 

Step 8) Now run  the Application in two Browser and check whether Chat or not

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend