ARTICLE

Count total number of page view in VB.NET

Posted by Satyapriya Nayak Articles | ASP.NET using VB.NET August 11, 2011
Here I will show you to count the total number of visitors enter to a website.
Reader Level:

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

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor