Wrox Programmer Forums
ASP.NET 4 General Discussion For ASP.NET 4 discussions not relating to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 4 General Discussion 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
Old March 29th, 2011, 08:00 AM
Authorized User
Join Date: Apr 2005
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default Hit counter

I have been trying to create a hit counter as follows,
create a global.asax page - inside it i have created an Application as below
void Application_Start(object sender, EventArgs e)
// Code that runs on application startup
Application["hitCounter"] = 0;

then in my code behind page of my hits page i have this

protectedvoid Page_Load(object sender, EventArgs e)
"hitCounter"] = Application["hitCounter" + 1];
Label1.Text =

And the error is cannot convert type object to string.

I have seen a video of how to do this using vb instead of c# and it works fine. Can anyone point me in the correct direction of the syntax for c#.

Many Thanks
Old March 29th, 2011, 09:17 AM
Friend of Wrox
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts

Try this:
Application["hitCounter"] = (int)Application["hitCounter"] + 1;
Label1.Text = Application["hitCounter"].ToString();

Om Prakash Pant
Click the "Thanks" button if this post helped you.
The Following User Says Thank You to om_prakash For This Useful Post:
markhh (March 29th, 2011)
Old March 29th, 2011, 01:39 PM
Authorized User
Join Date: Apr 2005
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts

Hi om_prakash, great reply, it works a treat.

Many many thanks

Similar Threads
Thread Thread Starter Forum Replies Last Post
hit counter alfredogirosi ASP.NET 3.5 Basics 1 April 14th, 2009 08:18 AM
hit counter alfredogirosi ASP.NET 3.5 Basics 0 April 13th, 2009 07:37 PM
Hit Counter Help! NeilS21 Classic ASP Databases 4 April 29th, 2005 06:59 AM

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