Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 29th, 2011, 08:00 AM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
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)
{
Application[
"hitCounter"] = Application["hitCounter" + 1];
Label1.Text =
(Application["hitCounter"]);}

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
Markhh
Reply With Quote
  #2 (permalink)  
Old March 29th, 2011, 09:17 AM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

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

__________________
Om Prakash Pant
Click the "Thanks" button if this post helped you.
Reply With Quote
The Following User Says Thank You to om_prakash For This Useful Post:
markhh (March 29th, 2011)
  #3 (permalink)  
Old March 29th, 2011, 01:39 PM
Authorized User
Points: 303, Level: 6
Points: 303, Level: 6 Points: 303, Level: 6 Points: 303, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: , , United Kingdom.
Posts: 71
Thanks: 23
Thanked 0 Times in 0 Posts
Default

Hi om_prakash, great reply, it works a treat.

Many many thanks
Markhh
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 06:00 PM.


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