User:Semipatel/sandbox

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

void Application_Start(object sender, EventArgs e)   { // Code that runs on application startup Application.Lock; Application["tusers"] = 0; Application["ousers"] = 0; 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 int tusers, ousers; Application.Lock; tusers = int.Parse(Application["tusers"].ToString)+1; ousers = int.Parse(Application["ousers"].ToString)+1; Application["tusers"] = tusers; Application["ousers"] = ousers; Application.UnLock; }

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. int ousers; Application.Lock; ousers = int.Parse(Application["ousers"].ToString) - 1; Application["ousers"] = ousers; Application.UnLock; }

Code:

using System;

public partial class _Default : System.Web.UI.Page {   protected void Page_Load(object sender, EventArgs e)    { string tusers, ousers; Application.Lock; tusers = Application["tusers"].ToString;Italic text ousers=Application["ousers"].ToString; Application.UnLock; TextBox1.Text = tusers; TextBox2.Text = ousers; }   protected void BtnLogOut_Click(object sender, EventArgs e)    { Session.Abandon; } }

Output:

Execute the application, copy the url and open the same url in other browsers. The result will be as shown below:

image2.gif'Bold text'Bold text

public class Sample : Control { private int currentIndex = 0;

protected override void OnInit(EventArgs e) { Page.RegisterRequiresControlState(this); base.OnInit(e); }

protected override object SaveControlState { return currentIndex != 0 ? (object)currentIndex : null; }

protected override void LoadControlState(object state) { if (state != null) { currentIndex = (int)state; }   } }