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


Top 5 Contributors of the Month
david stephan

Post New Resource Bookmark and Share   

Count total number of page view

Posted By:satyapriyanayak       Posted Date: March 25, 2013    Points: 40    Category:    URL: http://www.dotnetspark.com  

Count total number of page view
 

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 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>

 



     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Here

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