Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 9th, 2003, 07:49 PM
Authorized User
 
Join Date: Jun 2003
Location: Sylmar, CA, USA.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to gumgak
Default hit counter

I am using ASP.NET with C#.
i once saw the code that generates hit count using server control / session. it was really simple.

can anyone help me with this?
  #2 (permalink)  
Old July 10th, 2003, 01:07 PM
Authorized User
 
Join Date: Jun 2003
Location: Sylmar, CA, USA.
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to gumgak
Default

Following code works well for the session. however i need to find out how to track the number of visitors using web.conf. can anyone help?

<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Collections" %>
<%@ Import Namespace="System.ComponentModel" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.SessionState" %>
<%@ Import Namespace="System.IO" %>

<script language="C#" runat="server" >
    void Page_Load(object sender, System.EventArgs e)
    {
        int count = 0;
        if (!(Page.IsPostBack)){
            count = SessionHitCounter();
        }
        SessionCount.Text = Convert.ToString(count);
    }

    public int SessionHitCounter()
    {
       if (Session["HitCounter"] == null) {
          Session["HitCounter"] = 1;
       }
       else {
          Session["HitCounter"] = ((int) Session["HitCounter"]) + 1;
       }
       return ((int) Session["HitCounter"]);
    }

     void EnterBtn_Click(Object Src, EventArgs E)
    {
          // Populate the text box with the results from the call to the XML Web service method.
          int i = SessionHitCounter();
          SessionCount.Text = Convert.ToString(i);
    }

</script>

<HTML>
<HEAD>
<TITLE>counter test</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
</HEAD>
<BODY>
    <form runat="server" id="Form1">
        <asp:button text="Bump Up Counter" Onclick="EnterBtn_Click" runat=server ID="Button1" NAME="Button1"/>
        <p>
        hit counter:
        <ASP:LABEL ID="SessionCount" runat="server"></ASP:LABEL>
    </form>
</BODY>
</HTML>
  #3 (permalink)  
Old November 2nd, 2003, 12:44 AM
Authorized User
 
Join Date: Nov 2003
Location: Norco, CA, USA.
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you found an answer?
I have the same question and have entered the code in that question which is now one the Active Topics. Please look at it. I'm using a Session State object on the Global.aspx.cs page.
Where did you declare count, and SessionCount, and HitCount?


Sandy


Similar Threads
Thread Thread Starter Forum Replies Last Post
A Hit Counter, PLEASE HELP !!!!! ARD_40 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 April 23rd, 2006 06:25 AM
Hit Counter Help! NeilS21 Classic ASP Databases 4 April 29th, 2005 06:59 AM
Hit Counter mateenmohd HTML Code Clinic 7 September 28th, 2003 07:22 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.