Home > ASP.Net > Count Number of Online Users With Image

Count Number of Online Users With Image


Hi

try this example to display number of online users in my website

and display this number as image

In Global.ascx

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

<script runat="server">

void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application.Lock();
Application["Hits"] = 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
Server.ClearError();
}

void Session_Start(object sender, EventArgs e)
{
//--Lock the Application for concurrency issues
Application.Lock();
Application["Hits"] = Convert.ToInt32(Application["Hits"]) + 1;
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.
Application.Lock();
Application["Hits"] = Convert.ToInt32(Application["Hits"]) - 1;
Application.UnLock();
}

</script>

and in Master Page add Table control

protected void Page_Load(object sender, EventArgs e)
{
//-- for Hit Counter
string y = Application["Hits"].ToString().PadLeft(5, '0');
int z = 0;
char[] ch = y.ToCharArray();
Array.Reverse(ch);
foreach (char num in ch)
{
Image img = new Image();
img.ImageUrl = "~/Digits/" + num + ".gif";
yaser.Rows[0].Cells[z].Controls.Add(img);
z++;
}
}

so i add folder Digits and add pictures from 0 to 9

<fieldset>
Online User(s) now :<br />
<table id="yaser" runat="server" border="2"  dir="rtl" style="width: 124px">
               <tr>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
<td>
</td>
</tr>
</table>
</fieldset>

Good Luck

Advertisements
Categories: ASP.Net
  1. October 10, 2010 at 7:22 pm

    thanks,
    sir it help me out.

  2. yasserzaid
    October 14, 2010 at 8:11 pm

    @Munendra Kumar :- you are welcome hope my post helps you

  3. RAKESH
    January 7, 2013 at 1:28 pm

    Global.asxc,,,, this in not right name….name should me Global.ascx….

    • yasserzaid
      January 8, 2013 at 8:12 am

      @RAKESH : Ok sorry for that mistake … Thank you 🙂

  4. Rakesh
    September 1, 2015 at 5:08 pm

    welcom sir

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: