Here I will show you to count
the total number of visitors enter to a website.
Program
Default.aspx code
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 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 id="Head1" runat="server">
<title>Untitled
Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Label ID="Label2"
Text="Total no of
Visitors" runat="server" BackColor="#FFFFCC" ForeColor="#663300"></asp:Label>
<asp:Label ID="Label1" runat="server" Text="Label" BackColor="#66FFFF"
ForeColor="#FF3300"></asp:Label>
</form>
</body>
</html>
Default.aspx.vb code
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal
sender As Object,
ByVal e As
System.EventArgs)
Handles Me.Load
Dim result As Integer
result =
Convert.ToInt32((Application("usercount")))
Label1.Text =
Convert.ToString(result)
If (result < 10) Then
Label1.Text =
"000" + Label1.Text
ElseIf (result < 100) Then
Label1.Text =
"00" + Label1.Text
ElseIf (result < 1000) Then
Label1.Text =
"0" + Label1.Text
End If
End Sub
End Class
Global.asax code
<%@ Application Language="VB"
%>
<script runat="server">
Dim count As
Integer = 0
Sub Application_Start(ByVal sender
As Object,
ByVal e As EventArgs)
' Code that runs on application startup
Application("usercount")
= count
End Sub
Sub Application_End(ByVal sender
As Object,
ByVal e As EventArgs)
' Code that runs on application
shutdown
End Sub
Sub Application_Error(ByVal sender
As Object,
ByVal e As EventArgs)
' Code that runs when an unhandled
error occurs
End Sub
Sub Session_Start(ByVal sender
As Object,
ByVal e As EventArgs)
' Code that runs when a new session is
started
count =
Convert.ToInt32(Application("usercount"))
Application("usercount")
= count + 1
End Sub
Sub Session_End(ByVal sender
As Object,
ByVal e As EventArgs)
' 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.
End Sub
</script>
Thanks for reading