need help on creating no of views of a page functionality. [Resolved]

Posted by A4u6178 under C# on 6/7/2011 | Points: 10 | Views : 1979 | Status : [Member] | Replies : 10
Hi all,

I need help on creating no of views of a page functionality on my aspx page.

Thanks & Regards;
aaa



Responses

Posted by: Nithadeepak on: 6/7/2011 [Member] Bronze | Points: 50

Up
0
Down

Resolved
Application["hitcount"]=(int)Application["hitcount"]+1;


Nitha Deepak

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nithadeepak on: 6/7/2011 [Member] Bronze | Points: 25
Posted by: Susanthampy on: 6/7/2011 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Try this,

http://www.aspxtutorial.com/post/2011/01/11/Number-of-active-visitors-in-aspnet-web-site.aspx

Regards,
Susan

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u6178 on: 6/7/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Nithadeepak,

thanks for ur immediate reply,
I want no of views of a page (no of times a page loads)

Thanks & Regards;
aaa

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nithadeepak on: 6/7/2011 [Member] Bronze | Points: 25

Up
0
Down
try this,
in global.asax,
void Application_Start(object sender, EventArgs e) 

{ // Code that runs on application startup
Application["hitcount"] = 0;
}
.
.
.

In the page_load of the aspx page,add

Application["hitcount"]=Application["hitcount"]+1;


or else refer this,
http://forums.asp.net/t/1344167.aspx/1

Nitha Deepak

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u6178 on: 6/7/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Nithadeepak,

this following code em using in page load

 var views = Session["views"] = 1;


pageviewslbl.Text = "No Of Views:" + Session["views"].ToString();


Thanks & Regards;
aaa

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nithadeepak on: 6/7/2011 [Member] Bronze | Points: 25

Up
0
Down
Application - Stored on the server and shared for all users. Does not expire.Thats why we are using Application in this scenario.
So first you have to ad global.asax in your application and initialize Application["hitcount"] in Application_Start.

void Application_Start(object sender, EventArgs e) 

{ // Code that runs on application startup
Application["hitcount"] = 0;
}
.
.
.

then in the page load you can try

Application["hitcount"]=Application["hitcount"]+1;


pageviewslbl.Text=Application["hitcount"].ToString();


Nitha Deepak

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u6178 on: 6/7/2011 [Member] Starter | Points: 25

Up
0
Down
Em getting this error
Operator '+' cannot be applied to operands of type 'object' and 'int'



Thanks & Regards;
aaa

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u6178 on: 6/7/2011 [Member] Starter | Points: 25

Up
0
Down


The global asax:
void Application_Start(object sender, EventArgs e)

{
// Code that runs on application startup

Application["hitcount"] = 0;

}


the code behind:

 protected void Page_Load(object sender, EventArgs e)

{
Application["hitcount"] =(int) Application["hitcount"] + 1;
pageviewslbl.Text ="No Of Views : "+ Application["hitcount"].ToString();


Thanks & Regards;
aaa

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u6178 on: 6/7/2011 [Member] Starter | Points: 25

Up
0
Down
Thank u nithadeepak,


Thanks & Regards;
aaa

A4u6178, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response